threading problem with SSH2SFTPClient

maf@appgate.com maf@appgate.com
Tue, 4 Feb 2003 12:38:02 +0100 (CET)


--397199618-1649760492-1044358682=:18697
Content-Type: TEXT/PLAIN; CHARSET=us-ascii
Content-Disposition: INLINE

On  3 Feb, Daire Garvey wrote
> Hi there, I am using the mindterm source to copy lots of files using
> SSH2SFTPClient. Each file is transferred one at a time in its own
> connection. So before each transfer I create the SSH2Transport,
> SSH2Connection and SSH2SFTPClient, and after each transfer I call:
> 
> SSH2SFTPClient.terminate();
> SSHTransport.normalDisconnect("finished");
> 
> It seems that over time the number of threads being used by the
> process goes up and up 

Yes, SSH2SFTPClient leaks a thread for each connection. The attached
patch should fix it.

	/MaF
-- 
Martin Forssen <maf@appgate.com>              Development Manager
Phone: +46 31 7744361                         AppGate Network Security AB
--397199618-1649760492-1044358682=:18697
Content-Type: TEXT/PLAIN; NAME="SSH2SFTPClient.patch"
Content-Disposition: ATTACHMENT; FILENAME="SSH2SFTPClient.patch"

Index: SSH2SFTPClient.java
===================================================================
RCS file: /usr/site/share/cvsroot/mindterm/src/com/mindbright/ssh2/SSH2SFTPClient.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SSH2SFTPClient.java	2002/11/06 12:29:20	1.6
+++ SSH2SFTPClient.java	2003/01/22 07:41:55	1.7
@@ -202,6 +202,7 @@
     private int                version;
     private boolean            isBlocking;
     private boolean            isOpen;
+    private boolean            transmitterIsRunning = false;
 
     private Hashtable          replyLocks;
 
@@ -239,6 +240,10 @@
 	    session.close();
 	}
 	cancelAllAsync();
+	if (transmitterIsRunning) {
+	    txQueue.setBlocking(false);
+	    txQueue.setBlocking(true);
+	}
 	session = null;
 	if(pktPool != null) {
 	    // Be nice to the GC
@@ -716,6 +721,7 @@
 	receiver.setDaemon(true);
 	transmitter.start();
 	receiver.start();
+	transmitterIsRunning = true;
     }
 
     private void sftpTransmitLoop() {
@@ -731,6 +737,7 @@
 				      "session was probably closed");
 	    terminate();
 	}
+	transmitterIsRunning = false;
     }
 
     private void sftpReceiveLoop() {

--397199618-1649760492-1044358682=:18697--