Merge pull request #234 from dw/dmw

Fix one Latch race, one huge leak around fork
pull/246/head
dw 7 years ago committed by GitHub
commit bd9d9e3600
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -544,13 +544,13 @@ Setns
~~~~~
The ``setns`` method connects to Linux containers via `setns(2)
<https://linux.die.net/man/2/setns>`_. Unlike ``docker`` and ``lxc`` the
namespace transition is handled directly, ensuring optimal throughput to the
child. This is necessary for ``machinectl`` where only PTY channels are
<https://linux.die.net/man/2/setns>`_. Unlike :ref:`docker` and :ref:`LXC` the
namespace transition is handled internally, ensuring optimal throughput to the
child. This is necessary for :ref:`machinectl` where only PTY channels are
supported.
Utility programs must still be installed to discover the PID of the container's
root process.
A utility program must be installed to discover the PID of the container's root
process.
* ``mitogen_kind``: one of ``docker``, ``lxc`` or ``machinectl``.
* ``ansible_host``: Name of container as it is known to the corresponding tool

@ -981,6 +981,7 @@ class Latch(object):
closed = False
_waking = 0
_sockets = []
_allsockets = []
def __init__(self):
self._lock = threading.Lock()
@ -989,10 +990,9 @@ class Latch(object):
@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()
@ -1008,11 +1008,14 @@ class Latch(object):
return len(self._queue) == 0
def _tls_init(self):
if self._sockets:
# pop() must be atomic, which is true for GIL-equipped interpreters.
try:
return self._sockets.pop()
except IndexError:
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):

@ -798,7 +798,6 @@ class Context(mitogen.core.Context):
LOG.debug('%r.shutdown() sending SHUTDOWN', self)
latch = mitogen.core.Latch()
mitogen.core.listen(self, 'disconnect', lambda: latch.put(None))
self.send(
mitogen.core.Message(
handle=mitogen.core.SHUTDOWN,
@ -807,6 +806,7 @@ class Context(mitogen.core.Context):
if wait:
latch.get()
return latch
class RouteMonitor(object):

@ -77,8 +77,9 @@ def _run_command(args):
def get_docker_pid(path, name):
args = [path, 'inspect', '--format={{.State.Pid}}', name]
output = _run_command(args)
try:
return int(_run_command(args))
return int(output)
except ValueError:
raise Error("could not find PID from docker output.\n%s", output)
@ -132,7 +133,7 @@ class Stream(mitogen.parent.Stream):
if lxc_info_path:
self.lxc_info_path = lxc_info_path
if machinectl_path:
self.machinectl_path = lxc_attach_apth
self.machinectl_path = machinectl_path
# Order matters. https://github.com/karelzak/util-linux/commit/854d0fe/
NS_ORDER = ('ipc', 'uts', 'net', 'pid', 'mnt', 'user')

Loading…
Cancel
Save