[issue8184] multiprocessing.managers will not fail if listening ocket already in use
Charles-François Natali
report at bugs.python.org
Sat Jan 7 19:49:24 CET 2012
Charles-François Natali <neologix at free.fr> added the comment:
I noticed that if bind() fails (in this case with EADDRINUSE), the
socket isn't closed (FD leak).
Here's a patch.
----------
keywords: +patch
Added file: http://bugs.python.org/file24163/connection_error.diff
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8184>
_______________________________________
-------------- next part --------------
diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py
--- a/Lib/multiprocessing/connection.py
+++ b/Lib/multiprocessing/connection.py
@@ -575,10 +575,14 @@
'''
def __init__(self, address, family, backlog=1):
self._socket = socket.socket(getattr(socket, family))
- self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- self._socket.bind(address)
- self._socket.listen(backlog)
- self._address = self._socket.getsockname()
+ try:
+ self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+ self._socket.bind(address)
+ self._socket.listen(backlog)
+ self._address = self._socket.getsockname()
+ except OSError:
+ self._socket.close()
+ raise
self._family = family
self._last_accepted = None
More information about the Python-bugs-list
mailing list