Skip to content
Permalink
Browse files

core: fix monster fork FD leak

_sockets only refers to the idle sockets list, it doesn't refer to every
socket currently in use by a Latch, for example, the 2*16 used by e.g.
Ansible's sleeping service pool.
  • Loading branch information...
dw committed Apr 29, 2018
1 parent 7316c08 commit c0ced6d04a7b09a69ccde0e2280cf2f209656f80
Showing with 5 additions and 4 deletions.
  1. +5 −4 mitogen/core.py
@@ -981,6 +981,7 @@ class Latch(object):
closed = False
_waking = 0
_sockets = []
_allsockets = []

def __init__(self):
self._lock = threading.Lock()
@@ -989,10 +990,9 @@ def __init__(self):

@classmethod
def _on_fork(cls):
while cls._sockets:
rsock, wsock = cls._sockets.pop()
rsock.close()
wsock.close()
cls._sockets = []
while cls._allsockets:
cls._allsockets.pop().close()

def close(self):
self._lock.acquire()
@@ -1015,6 +1015,7 @@ def _tls_init(self):
rsock, wsock = socket.socketpair()
set_cloexec(rsock.fileno())
set_cloexec(wsock.fileno())
self._allsockets.extend((rsock, wsock))
return rsock, wsock

def get(self, timeout=None, block=True):

0 comments on commit c0ced6d

Please sign in to comment.
You can’t perform that action at this time.