From a56de25df55b5ec5d41cc97e7a9b8c466718366b Mon Sep 17 00:00:00 2001 From: Ricardo Carrillo Cruz Date: Sat, 13 Jan 2018 15:54:44 +0100 Subject: [PATCH] Fix persistent command timeout handling (#34791) * Fix persistent command timeout handling We were using play context timeout on ansible-connect to set the persistent command timeout handler. Thus, we were ignoring the persistent_command_timeout setting. Moreover, even by changing that on ansible-connection, were again overriding it on cliconf send_command, since in a same process we can just set a single alarm and cliconf send_command alarm setup is executed after ansible-connection alarm setup. * Remove alarm setting on cliconf send_command The alarm is set regardless before it is executed by ansible-connection. Setting an alarm again, overrides/disables the previous ones as a single process can just have a single alarm set. * Move the setting of persistent command timeout to network_cli We do also use ansible-connection for connection local, so if a user provides a timeout via provider that would be ignored if we set the value on ansible-connection. Moving that logic to network_cli plugin constructor makes both connections to work. * Remove debug statements * Set the persistent command timeout on task_executor We can't set the timeout on ansible-connection nor network_cli, otherwise tasks using provider timeout won't work. --- lib/ansible/executor/task_executor.py | 1 + lib/ansible/plugins/cliconf/__init__.py | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 086db41935e..9adc7e13523 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -743,6 +743,7 @@ class TaskExecutor: self._play_context.set_options_from_plugin(connection) if any(((connection.supports_persistence and C.USE_PERSISTENT_CONNECTIONS), connection.force_persistence)): + self._play_context.timeout = C.PERSISTENT_COMMAND_TIMEOUT display.vvvv('attempting to start connection', host=self._play_context.remote_addr) display.vvvv('using connection plugin %s' % connection.transport, host=self._play_context.remote_addr) socket_path = self._start_connection() diff --git a/lib/ansible/plugins/cliconf/__init__.py b/lib/ansible/plugins/cliconf/__init__.py index 44696ef0d4b..0aaca9e47fb 100644 --- a/lib/ansible/plugins/cliconf/__init__.py +++ b/lib/ansible/plugins/cliconf/__init__.py @@ -106,11 +106,7 @@ class CliconfBase(with_metaclass(ABCMeta, object)): if answer is not None: kwargs['answer'] = to_bytes(answer) - if not signal.getsignal(signal.SIGALRM): - signal.signal(signal.SIGALRM, self._alarm_handler) - signal.alarm(self._connection._play_context.timeout) resp = self._connection.send(**kwargs) - signal.alarm(0) return resp def get_base_rpc(self):