Rev 4742: More thread leak tracking help. in file:///home/vila/src/bzr/bugs/392127-thread-leak/

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri Oct 9 13:10:20 BST 2009


At file:///home/vila/src/bzr/bugs/392127-thread-leak/

------------------------------------------------------------
revno: 4742
revision-id: v.ladeuil+lp at free.fr-20091009121020-9zlxqc2hz3esbd61
parent: v.ladeuil+lp at free.fr-20091008172024-8i6w17137n1b4108
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 392127-thread-leak
timestamp: Fri 2009-10-09 14:10:20 +0200
message:
  More thread leak tracking help.
  
  * bzrlib/tests/http_server.py:
  (TestingHTTPServerMixin.serve): Add more trace under the -Ethreads
  flag.
  (HttpServer.tearDown): Report the hangs instead of hanging.
-------------- next part --------------
=== modified file 'bzrlib/tests/http_server.py'
--- a/bzrlib/tests/http_server.py	2009-10-08 17:19:38 +0000
+++ b/bzrlib/tests/http_server.py	2009-10-09 12:10:20 +0000
@@ -31,6 +31,7 @@
 import urlparse
 
 from bzrlib import (
+    errors,
     tests,
     transport,
     )
@@ -335,7 +336,10 @@
     def serve(self):
         self.serving = True
         self.is_shut_down.clear()
+        # Ensure that we will not stay blocked in listen()
         self.socket.settimeout(1)
+        if 'threads' in tests.selftest_debug_flags:
+            print 'Starting %r' % (self.server_address,)
         while self.serving:
             try:
                 # Really a connection but the python framework is generic and
@@ -352,6 +356,8 @@
                    pass
                else:
                    raise
+        if 'threads' in tests.selftest_debug_flags:
+            print 'Closing  %r' % (self.server_address,)
         # Let's close the listening socket
         self.server_close()
         self.is_shut_down.set()
@@ -619,9 +625,15 @@
 
     def tearDown(self):
         """See bzrlib.transport.Server.tearDown."""
-        self._http_running = False
         self._httpd.shutdown()
-        self._http_thread.join()
+        self._http_thread.join(5.0)
+        if self._http_thread.is_alive():
+            # The timeout expired without joining the thread, the server thread
+            # is therefore stucked and that's a failure as far as the test is
+            # concerned, we used to hang here, but that wasn't very productive.
+            raise AssertionError('http server at %r hanged'
+                                 % (self._httpd.server_address,))
+
         if 'threads' in tests.selftest_debug_flags:
             print 'Thread  joined: %s' % (self._http_thread.ident,)
         del self._http_thread



More information about the bazaar-commits mailing list