Java JSch library never closes SSH connections?
Hi guys
I'm trying to use JSch from the official Oracle Java SE 1.8 JVM for high numbers (tens of thousands) of file transfers between servers on the internet over SFTP.
Both machines on both sides run a fully updated Centos 7 instance. Both consistently run out of file handles due to JSch never closing any connections it uses, even with very explicit exiting and disconnecting of JSch exec and sftp channels, or even killing the Java app that was using JSch to create these connections. I have posted the code, and it apparently passes muster.
The strange thing is I've noticed if I close the Java application from which I opened the SSH connections, on the target Centos 7 server the SSH connections it opened via JSCh is still there if I run "netstat -tnpa | grep ssh".
If I completely shut down the PC that ran JSCh to open the connections on the target Centos 7 server, the connections are still there, reported by "netstat -tnpa | grep ssh".
If I make a putty or WinSCP connection from that PC to the Centos 7 server and I close putty or WinSCP, their SSH and SFTP connections are correctly dropped and there is one less SSH connection reported by "netstat -tnpa | grep ssh".
The ONLY way to ever flush dead "JSch-created" SSH sessions from the Centos 7 system is to physically reboot the Centos 7 machine.
This makes it impossible to use JSch to transfer the files - it will only transfer a set amount and the target Centos 7 machine then runs out of file handles and all file transfer stops as JSch never, ever flushes or actually closes an SSH session on the Centos 7 machine connected to... even closing the Java application that used JSch to open those sessions has no effect, the sessions stay open.
I've also left it for several days, SSH sessions created via JSch from the 1.8 Java SE JVM on Monday, are still there, in their thousands, on Friday - each single one.
Anybody got ANY idea why (and how) JSch can create "indestructible" SSH sessions on Centos 7's OpenSSH server?
How can I get JSch to -really- close an SSH connection?
Thanks!
Last edited by rylan76; 08-22-2016 at 03:03 AM.
|