diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2008-03-09 19:03:42 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2008-03-09 19:03:42 (GMT) |
commit | 0098c9d60997f40c8e75714db9963337dc834378 (patch) | |
tree | e02b370772cfd065554c350a350e8ccc50af4543 /Lib | |
parent | 5bb647dfa83945d8f7788a58769f9240b1a66340 (diff) | |
download | cpython-0098c9d60997f40c8e75714db9963337dc834378.zip cpython-0098c9d60997f40c8e75714db9963337dc834378.tar.gz cpython-0098c9d60997f40c8e75714db9963337dc834378.tar.bz2 |
Introduce a lock to fix a race condition which caused an exception in the test.
Some buildbots were consistently failing (e.g., amd64).
Also remove a couple of semi-colons.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_ssl.py | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py index a82aa6d..f5ae026 100644 --- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -337,6 +337,7 @@ else: # we assume the certfile contains both private key and certificate self.certfile = certfile self.active = False + self.active_lock = threading.Lock() self.allow_reuse_address = True def get_request (self): @@ -361,23 +362,32 @@ else: # We want this to run in a thread, so we use a slightly # modified version of "forever". self.active = True - while self.active: + while 1: try: - self.handle_request() + # We need to lock while handling the request. + # Another thread can close the socket after self.active + # has been checked and before the request is handled. + # This causes an exception when using the closed socket. + with self.active_lock: + if not self.active: + break + self.handle_request() except socket.timeout: pass except KeyboardInterrupt: self.server_close() return except: - sys.stdout.write(''.join(traceback.format_exception(*sys.exc_info()))); + sys.stdout.write(''.join(traceback.format_exception(*sys.exc_info()))) + break def server_close(self): # Again, we want this to run in a thread, so we need to override # close to clear the "active" flag, so that serve_forever() will # terminate. - HTTPServer.server_close(self) - self.active = False + with self.active_lock: + HTTPServer.server_close(self) + self.active = False class RootedHTTPRequestHandler(SimpleHTTPRequestHandler): @@ -664,7 +674,7 @@ else: not in cert['subject']): raise test_support.TestFailed( "Missing or invalid 'organizationName' field in certificate subject; " - "should be 'Python Software Foundation'."); + "should be 'Python Software Foundation'.") s.close() finally: server.stop() |