From b0309b539c5b74911296ca75f77ccb4aa78dcb40 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sun, 29 Apr 2018 09:53:16 +0100 Subject: [PATCH] ansible: disable interpreter recycling for connections. Must explicitly specify enable_lru=True in ContextService.get() to trigger recycling. --- ansible_mitogen/connection.py | 1 + ansible_mitogen/services.py | 4 ++-- docs/ansible.rst | 4 ---- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/ansible_mitogen/connection.py b/ansible_mitogen/connection.py index 192c6dd4..59e82695 100644 --- a/ansible_mitogen/connection.py +++ b/ansible_mitogen/connection.py @@ -134,6 +134,7 @@ def _connect_setns(spec): def _connect_sudo(spec): return { 'method': 'sudo', + 'enable_lru': True, 'kwargs': { 'username': spec['become_user'], 'password': spec['become_pass'], diff --git a/ansible_mitogen/services.py b/ansible_mitogen/services.py index c3157bf0..13b8d044 100644 --- a/ansible_mitogen/services.py +++ b/ansible_mitogen/services.py @@ -167,7 +167,7 @@ class ContextService(mitogen.service.Service): del self._response_by_key[key] del self._refs_by_context[context] del self._key_by_context[context] - if lru: + if lru and context in lru: lru.remove(context) if new_context: lru.append(new_context) @@ -256,7 +256,7 @@ class ContextService(mitogen.service.Service): raise Error('unsupported method: %(transport)s' % spec) context = method(via=via, **spec['kwargs']) - if via: + if via and spec.get('enable_lru'): self._update_lru(context, spec, via) else: # For directly connected contexts, listen to the associated diff --git a/docs/ansible.rst b/docs/ansible.rst index 3abf6f9c..d28c0de0 100644 --- a/docs/ansible.rst +++ b/docs/ansible.rst @@ -213,10 +213,6 @@ container. as duplicate connections between hops, due to not perfectly replicating the configuration Ansible would normally use for the intermediary. - * The extension does not understand the difference between a delegated - connection and a ``become_user``. If interpreter recycling kicks in, a - delegated connection could be prematurely recycled. - To enable connection delegation, set ``mitogen_via=`` on the command line, or as host and group variables.