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

Session thread stays open forever #661

Open
ochakov opened this issue Sep 30, 2024 · 2 comments
Open

Session thread stays open forever #661

ochakov opened this issue Sep 30, 2024 · 2 comments

Comments

@ochakov
Copy link

ochakov commented Sep 30, 2024

Using version 02.19 with Apache commons.
In our application, we frequently connect to a third party SFTP server. Looks like, sometime, the server fails to retrieve a file. In this case, we close the connection (calling disconnect) after timeout, but there is a session thread that is never closed.

sun.nio.ch.SocketDispatcher.read0 ( native code )
sun.nio.ch.SocketDispatcher.read ( SocketDispatcher.java:47 )
sun.nio.ch.NioSocketImpl.tryRead ( NioSocketImpl.java:266 )
sun.nio.ch.NioSocketImpl.implRead ( NioSocketImpl.java:317 )
sun.nio.ch.NioSocketImpl.read ( NioSocketImpl.java:355 )
sun.nio.ch.NioSocketImpl$1.read ( NioSocketImpl.java:808 )
java.net.Socket$SocketInputStream.read ( Socket.java:966 )
com.jcraft.jsch.IO.getByte ( IO.java:95 )
com.jcraft.jsch.Session.read ( Session.java:1231 )
com.jcraft.jsch.Session.run ( Session.java:1783 )
com.jcraft.jsch.Session$$Lambda$3301/0x00007f4f8789e650.run ( unknown source )
java.lang.Thread.run ( Thread.java:840 )

After a while, we have thousands of these threads staying open forever until we restart the app.
Looks like the InputStream returned from Socket must be checked isAvailable before trying to read.

@norrisjeremy
Copy link
Contributor

Hi @ochakov,

It sounds like you need to call Session.setTimeout() with an appropriate value.

Thanks,
Jeremy

@ochakov
Copy link
Author

ochakov commented Sep 30, 2024

We are setting session timeout of 1 minute.

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