Issue #8184: Fix a potential file descriptor leak when a

multiprocessing.Connection socket can't be bound.
This commit is contained in:
Charles-François Natali 2012-02-04 15:12:08 +01:00
parent d85d0e7247
commit edc67feaa4
1 changed files with 8 additions and 4 deletions

View File

@ -575,10 +575,14 @@ class SocketListener(object):
'''
def __init__(self, address, family, backlog=1):
self._socket = socket.socket(getattr(socket, family))
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