Rev 6190: If someone does manage to connect while we are shutting down, close the connection. in http://bazaar.launchpad.net/~jameinel/bzr/2.5-soft-hangup-795025

John Arbash Meinel john at arbash-meinel.com
Fri Sep 23 17:08:22 UTC 2011


At http://bazaar.launchpad.net/~jameinel/bzr/2.5-soft-hangup-795025

------------------------------------------------------------
revno: 6190
revision-id: john at arbash-meinel.com-20110923170811-gvo7k8ufg18lawan
parent: john at arbash-meinel.com-20110923165912-zzk334gqk1pxmzk2
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.5-soft-hangup-795025
timestamp: Fri 2011-09-23 19:08:11 +0200
message:
  If someone does manage to connect while we are shutting down, close the connection.
  Also, check if the server already knows its stopped, rather than waiting on the connection.
  (It can take a second or so for the OS to say that it really cannot connect to a closed socket.)
  
  There is one more failure now.
  Specifically: test_graceful_shutdown_waits_for_clients_to_stop.
  Because server._stop_gracefully() now tells client handlers to _stop_gracefully, and we
  don't actually have an active rpc in progress, the client can stop before we test
  that the server is waiting for it to stop.
-------------- next part --------------
=== modified file 'bzrlib/smart/server.py'
--- a/bzrlib/smart/server.py	2011-09-23 16:40:32 +0000
+++ b/bzrlib/smart/server.py	2011-09-23 17:08:11 +0000
@@ -221,6 +221,7 @@
                             trace.warning("listening socket error: %s", e)
                     else:
                         if self._should_terminate:
+                            conn.close()
                             break
                         self.serve_conn(conn, thread_name_suffix)
                     # Cleanout any threads that have finished processing.

=== modified file 'bzrlib/tests/test_smart_transport.py'
--- a/bzrlib/tests/test_smart_transport.py	2011-09-23 16:59:12 +0000
+++ b/bzrlib/tests/test_smart_transport.py	2011-09-23 17:08:11 +0000
@@ -1122,8 +1122,19 @@
         """Connect to the server, and then hang up.
         That way it doesn't sit waiting for 'accept()' to timeout.
         """
-        client_sock = self.connect_to_server(server)
-        client_sock.close()
+        # If the server has already signaled that the socket is closed, we
+        # don't need to try to connect to it. Not being set, though, the server
+        # might still close the socket while we try to connect to it. So we
+        # still have to catch the exception.
+        if server._stopped.isSet():
+            return
+        try:
+            client_sock = self.connect_to_server(server)
+            client_sock.close()
+        except socket.error, e:
+            # If the server has hung up already, that is fine.
+            self.fail(str(e))
+            pass
 
     def say_hello(self, client_sock):
         """Send the 'hello' smart RPC, and expect the response."""
@@ -1132,11 +1143,7 @@
 
     def shutdown_server_cleanly(self, server, server_thread):
         server._stop_gracefully()
-        try:
-            self.connect_to_server_and_hangup(server)
-        except socket.error:
-            # If the server has hung up already, that is fine.
-            pass
+        self.connect_to_server_and_hangup(server)
         server._stopped.wait()
         server._fully_stopped.wait()
         server_thread.join()



More information about the bazaar-commits mailing list