Rev 5274: Factor out socket exception handling during server shutdown. in file:///home/vila/src/bzr/experimental/leaking-tests/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Mon Jun 7 15:25:20 BST 2010
At file:///home/vila/src/bzr/experimental/leaking-tests/
------------------------------------------------------------
revno: 5274
revision-id: v.ladeuil+lp at free.fr-20100607142519-d37kawz1w1btjym3
parent: v.ladeuil+lp at free.fr-20100607140519-b4jdekuz1ln9ocy8
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: propagate-exceptions
timestamp: Mon 2010-06-07 16:25:19 +0200
message:
Factor out socket exception handling during server shutdown.
* bzrlib/tests/test_server.py:
(TestingTCPServerMixin.ignored_exceptions_during_shutdown): Factor
out the exceptions that can occur during server shutdown. This
should be used both for the server and client connections threads
as well as the main thread itself (since the socket exception can
be raised in any thread, at least on windows).
(TestingTCPServerMixin.shutdown_client_socket): Simplified.
(TestingTCPServerInAThread.stop_server): Install the exception handler.
-------------- next part --------------
=== modified file 'bzrlib/tests/test_server.py'
--- a/bzrlib/tests/test_server.py 2010-06-07 14:05:19 +0000
+++ b/bzrlib/tests/test_server.py 2010-06-07 14:25:19 +0000
@@ -372,6 +372,16 @@
self.serving.clear()
raise
+ def ignored_exceptions_during_shutdown(self, e):
+ if sys.platform == 'win32':
+ accepted_errnos = [errno.WSAEBADF, errno.WSAENOTCONN,
+ errno.WSAECONNRESET]
+ else:
+ accepted_errnos = [errno.EBADF, errno.ENOTCONN, errno.ECONNRESET]
+ if isinstance(e, socket.error) and e[0] in accepted_errnos:
+ return True
+ return False
+
# The following methods are called by the main thread
def stop_client_connections(self):
@@ -389,18 +399,13 @@
This should be called only when no other thread is trying to use the
socket.
"""
+ # The request process has been completed, the thread is about to
+ # die, let's shutdown the socket if we can.
try:
- # The request process has been completed, the thread is about to
- # die, let's shutdown the socket if we can.
sock.shutdown(socket.SHUT_RDWR)
sock.close()
- except (socket.error, select.error), e:
- accepted_errnos = [errno.EBADF, errno.ENOTCONN, errno.ECONNRESET]
- if sys.platform == 'win32':
- accepted_errnos.extend([errno.WSAEBADF, errno.WSAENOTCONN,
- errno.WSAECONNRESET])
- if e[0] in accepted_errnos:
- # Right, the socket is already down
+ except Exception, e:
+ if self.ignored_exceptions(e):
pass
else:
raise
@@ -550,9 +555,10 @@
return
try:
# The server has been started successfully, shut it down now. As
- # soon as we stop serving, no more connection are accepted except
- # one to get out of the blocking listen.
+ # soon as we stop serving, no more connection are accepted.
self.server.serving.clear()
+ self.set_ignored_exceptions(
+ self.server.ignored_exceptions_during_shutdown)
# The server is listening for a last connection, let's give it:
last_conn = None
try:
More information about the bazaar-commits
mailing list