From 38a553d42d85861dd9c9eab5039080a9c6928e1b Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sun, 27 Jan 2019 18:46:03 +0000 Subject: [PATCH] issue #490: prevent double close() destroying unrelated Connection. --- ansible_mitogen/connection.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ansible_mitogen/connection.py b/ansible_mitogen/connection.py index cdb83c61..bf1b0747 100644 --- a/ansible_mitogen/connection.py +++ b/ansible_mitogen/connection.py @@ -747,12 +747,16 @@ class Connection(ansible.plugins.connection.ConnectionBase): self.broker = None self.router = None - # #420: Ansible executes "meta" actions in the top-level process, - # meaning "reset_connection" will cause :class:`mitogen.core.Latch` FDs - # to be cached and erroneously shared by children on subsequent - # WorkerProcess forks. To handle that, call on_fork() to ensure any - # shared state is discarded. - mitogen.fork.on_fork() + # #420: Ansible executes "meta" actions in the top-level process, + # meaning "reset_connection" will cause :class:`mitogen.core.Latch` + # FDs to be cached and erroneously shared by children on subsequent + # WorkerProcess forks. To handle that, call on_fork() to ensure any + # shared state is discarded. + # #490: only attempt to clean up when it's known that some + # resources exist to cleanup, otherwise later __del__ double-call + # to close() due to GC at random moment may obliterate an unrelated + # Connection's resources. + mitogen.fork.on_fork() def close(self): """