ansible / ansible-runner

A tool and python library that helps when interfacing with Ansible directly or as part of another system whether that be through a container image interface, as a standalone tool, or as a Python module that can be imported. The goal is to provide a stable and consistent interface abstraction to Ansible.
Other
969 stars 357 forks source link

Restore original signal handlers in finished_callback #1402

Open bbatliner-ocient opened 2 weeks ago

bbatliner-ocient commented 2 weeks ago

The change in #862 added signal handlers for SIGINT and SIGTERM that may replace any existing SIGINT or SIGTERM handlers set by the process. Those existing handlers are not restored when the ansible_runner.run call finishes.

The solution here uses the finished_callback to restore the handlers. We're relying on the finished_callback actually getting called, which I'm not sure is a real guarantee. I'd be open to a solution that uses context managers or try-finally if we can figure out the right refactoring / where to put the try-finally semantics.

We are solving this problem today by using an ExitStack and a custom cancel_callback (that basically implements the same SIGINT/SIGTERM cancellation behavior as #862) that guarantees to restore the original handlers after the call completes.


TODOS