Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jsch connections getting stuck #54

Open
manishbansal8843 opened this issue Jul 18, 2021 · 3 comments
Open

Jsch connections getting stuck #54

manishbansal8843 opened this issue Jul 18, 2021 · 3 comments

Comments

@manishbansal8843
Copy link

manishbansal8843 commented Jul 18, 2021

I saw in readme that you have ported the fix to an issue in 0.1.59 where conmections are stuck. I faced the same issue but feels like the solution you added is not upto the mark.

I have raised the pr in original repo. May be you want to take a look. And if it looks fine to you, will be happy to raise it for you as well.

is/jsch#39

Issue link
https://sourceforge.net/p/jsch/mailman/message/36872566/

@norrisjeremy
Copy link
Contributor

Hi @manishbansal8843,
I left a question on is/jsch#39 to try and better understand the proposed change.

@norrisjeremy
Copy link
Contributor

Hi @manishbansal8843,

I believe I understand your analysis of this issue. When I have some free time, I hope to try and replicate the original issue and compare your suggested fix versus the original fix included in 0.1.59.

Thanks,
Jeremy

@norrisjeremy
Copy link
Contributor

Hi @manishbansal8843,

I tested with the original fix that was included in 0.1.59 and instead with your suggested fix. However, it still resulted in deadlocks:

"Connect thread localhost session" #19 daemon prio=5 os_prio=31 tid=0x00007fb84e88c800 nid=0x9a03 in Object.wait() [0x0000700004521000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
	at java.lang.Object.wait(Native Method)
	at java.io.PipedInputStream.awaitSpace(PipedInputStream.java:273)
	at java.io.PipedInputStream.receive(PipedInputStream.java:231)
	- locked <0x000000067d5b86a0> (a com.jcraft.jsch.Channel$MyPipedInputStream)
	at java.io.PipedOutputStream.write(PipedOutputStream.java:149)
	at com.jcraft.jsch.IO.put(IO.java:65)
	at com.jcraft.jsch.Channel.write(Channel.java:442)
	at com.jcraft.jsch.Session.run(Session.java:1780)
	at java.lang.Thread.run(Thread.java:748)

"main" #1 prio=5 os_prio=31 tid=0x00007fb84d00f000 nid=0x2303 in Object.wait() [0x00007000023bb000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
	at java.lang.Object.wait(Native Method)
	at java.io.PipedInputStream.read(PipedInputStream.java:326)
	- eliminated <0x000000067d5b8b68> (a com.jcraft.jsch.Channel$MyPipedInputStream)
	at java.io.PipedInputStream.read(PipedInputStream.java:377)
	- locked <0x000000067d5b8b68> (a com.jcraft.jsch.Channel$MyPipedInputStream)
	at com.jcraft.jsch.ChannelSftp.fill(ChannelSftp.java:2866)
	at com.jcraft.jsch.ChannelSftp.header(ChannelSftp.java:2892)
	at com.jcraft.jsch.ChannelSftp.checkStatus(ChannelSftp.java:2429)
	at com.jcraft.jsch.ChannelSftp.access$300(ChannelSftp.java:36)
	at com.jcraft.jsch.ChannelSftp$1.flush(ChannelSftp.java:850)
	at com.jcraft.jsch.ChannelSftp$1.write(ChannelSftp.java:801)
	at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
	at java.io.BufferedOutputStream.write(BufferedOutputStream.java:121)
	- eliminated <0x000000067d5b89a8> (a org.apache.commons.vfs2.provider.sftp.SftpFileObject$SftpOutputStream)
	at org.apache.commons.vfs2.util.MonitorOutputStream.write(MonitorOutputStream.java:123)
	- locked <0x000000067d5b89a8> (a org.apache.commons.vfs2.provider.sftp.SftpFileObject$SftpOutputStream)
	at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
	at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
	- eliminated <0x000000067d5b8980> (a org.apache.commons.vfs2.provider.DefaultFileContent$FileContentOutputStream)
	at org.apache.commons.vfs2.util.MonitorOutputStream.write(MonitorOutputStream.java:123)
	- locked <0x000000067d5b8980> (a org.apache.commons.vfs2.provider.DefaultFileContent$FileContentOutputStream)
	at org.apache.commons.vfs2.provider.DefaultFileContent.write(DefaultFileContent.java:805)
	at org.apache.commons.vfs2.provider.DefaultFileContent.write(DefaultFileContent.java:784)
	at org.apache.commons.vfs2.provider.DefaultFileContent.write(DefaultFileContent.java:755)
	at org.apache.commons.vfs2.provider.DefaultFileContent.write(DefaultFileContent.java:771)
	at org.apache.commons.vfs2.FileUtil.copyContent(FileUtil.java:37)
	at org.apache.commons.vfs2.provider.AbstractFileObject.copyFrom(AbstractFileObject.java:295)
	at SftpCopyDeadlock.main(SftpCopyDeadlock.java:42)

I'm not exactly sure why it still deadlocked, but my guess is that with the additional call to flush() that you suggested, it ends up being possible to read from the PipedInputstream and write to it's linked PipedOutputStream from within the main thread, which results in a deadlock, since the PipedInputStream & PipedOutputstream are never supposed to be utilized by the same thread.

Thanks,
Jeremy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants