SSH connection hanging on logout

John Bowman bowman at math.ualberta.ca
Wed May 16 18:18:03 EST 2001


The following is a CORRECTION, with a REVISED PATCH, to my message posted
to this list on 2001-05-15 2:55:37.

Here is a new version of the hang-on-exit patch (2001-05-08 23:52:24), which:

1. fixes the hang-on-exit bug under Protocol 2 (without data loss);
2. does not exit if there are unterminated X applications;
3. exits the session when all X applications have closed.

Of these three tests, Openssh-2.9p1 under Protocol 2 passes only the second 
one. The third item is another type of hanging bug in Openssh, as is
demonstrated by the following test:

ssh -2 host
xterm -e sleep 20 &
exit

Even after the xsession terminates, the ssh session is left hanging forever.
The correct behaviour is to wait 20 seconds for the X application to close
and then exit.

-- John Bowman

University of Alberta
http://www.math.ualberta.ca/~bowman

P.S. Since the hang-on-exit patch is only effective under Protocol 2,
a conditional to the call to chan_shutdown_read() has been added.

 

diff -ur openssh-2.9p1/channels.c openssh-2.9p1J/channels.c
--- openssh-2.9p1/channels.c	Tue Apr 17 12:14:35 2001
+++ openssh-2.9p1J/channels.c	Wed May 16 01:22:16 2001
@@ -333,6 +333,9 @@
 		xfree(c->remote_name);
 		c->remote_name = NULL;
 	}
+
+	if(channel_find_open() == -1)
+		shutdown(packet_get_connection_out(), SHUT_RDWR);
 }
 
 /*
@@ -1137,6 +1140,15 @@
 			continue;
 		if (ftab[c->type] == NULL)
 			continue;
+		if(c->istate == CHAN_INPUT_OPEN && c->rfd == -1) {
+			int type=c->type;
+			c->type=SSH_CHANNEL_CLOSED;
+			if(channel_find_open() == -1)
+			  	shutdown(packet_get_connection_out(),
+					 SHUT_RDWR);
+			c->type=type;
+			continue;
+		}
 		(*ftab[c->type])(c, readset, writeset);
 		if (chan_is_dead(c)) {
 			/*
diff -ur openssh-2.9p1/clientloop.c openssh-2.9p1J/clientloop.c
--- openssh-2.9p1/clientloop.c	Fri Apr 20 06:50:51 2001
+++ openssh-2.9p1J/clientloop.c	Wed May 16 01:22:16 2001
@@ -440,9 +440,13 @@
 		len = read(connection_in, buf, sizeof(buf));
 		if (len == 0) {
 			/* Received EOF.  The remote host has closed the connection. */
-			snprintf(buf, sizeof buf, "Connection to %.300s closed by remote host.\r\n",
-				 host);
-			buffer_append(&stderr_buffer, buf, strlen(buf));
+/* 
+ * This message duplicates the one already in client_loop().
+ *
+ *			snprintf(buf, sizeof buf, "Connection to %.300s closed by remote host.\r\n",
+ *				 host);
+ *			buffer_append(&stderr_buffer, buf, strlen(buf));
+ */			
 			quit_pending = 1;
 			return;
 		}
diff -ur openssh-2.9p1/nchan.c openssh-2.9p1J/nchan.c
--- openssh-2.9p1/nchan.c	Tue Apr  3 07:02:48 2001
+++ openssh-2.9p1J/nchan.c	Wed May 16 01:22:16 2001
@@ -56,7 +56,7 @@
 
 /* helper */
 static void	chan_shutdown_write(Channel *c);
-static void	chan_shutdown_read(Channel *c);
+void		chan_shutdown_read(Channel *c);
 
 /*
  * SSH1 specific implementation of event functions
@@ -479,7 +479,7 @@
 		c->wfd = -1;
 	}
 }
-static void
+void
 chan_shutdown_read(Channel *c)
 {
 	if (compat20 && c->type == SSH_CHANNEL_LARVAL)
diff -ur openssh-2.9p1/nchan.h openssh-2.9p1J/nchan.h
--- openssh-2.9p1/nchan.h	Sun Mar  4 23:16:12 2001
+++ openssh-2.9p1J/nchan.h	Wed May 16 01:22:16 2001
@@ -88,4 +88,5 @@
 
 void    chan_init_iostates(Channel * c);
 void	chan_init(void);
+void	chan_shutdown_read(Channel *c);
 #endif
diff -ur openssh-2.9p1/session.c openssh-2.9p1J/session.c
--- openssh-2.9p1/session.c	Wed Apr 18 09:29:34 2001
+++ openssh-2.9p1J/session.c	Wed May 16 02:05:12 2001
@@ -1960,6 +1960,9 @@
 	 */
 	if (c->ostate != CHAN_OUTPUT_CLOSED)
 		chan_write_failed(c);
+	if (c->istate != CHAN_INPUT_CLOSED && compat20) {
+		chan_shutdown_read(c);
+	}
 	s->chanid = -1;
 }
 



More information about the openssh-unix-dev mailing list