GUnicorn - Uvicorn - Flask - Ansible Playbook fails #2418
Unanswered
gitsridhar
asked this question in
Q&A
Replies: 1 comment 1 reply
-
If we use Python 3.8 instead of Python 3.9, this problem disappears. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Initial Checks
Discussion Link
Description
We have a python application executing Ansible playbook running under Gunicorn -> Uvicorn -> Flask environment. This application responds to http/https requests and it fails while executing ansible playbook.
The error message is from ansible code, 'A worker was found in a dead state, rc=0'. This problem is found to be from /lib/python3.9/site-packages/ansible/executor/task_queue_manager.py (has_dead_workers method).
The _wait_on_pending_results() function will generate an AnsibleError exception ("A worker was found in a dead state") when has_dead_workers() returns True
3456567 0.000158 exit_group(1) = ?
3456567 0.000008 +++ exited with 1 +++
3456441 0.000044 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=3456567, si_uid=0, si_status=1, si_utime=1, si_stime=2} ---
3456441 0.000061 wait4(3456567, [{WIFEXITED(s) && WEXITSTATUS(s) == 1}], WNOHANG, NULL) = 3456567
Ansible uses an unique thread for each task described in the playbook and one by one
When we run with uvicorn, each thread exits with si_status = 1
The test to know if the thread exits in error (and therefore we stop everything) is carried out in a loop but with other exit checks.
So it all depends on the timing of each check.
This explains why ansible exits with an error (A worker was found in a dead state), on one task or another. Is random
But the main question: why the si_status is equal to 1
When the ansible playbook is executed directly, there is no problem.
This problem is reproducible with the following command:
uvicorn --host 10.241.88.185 --port 8080 --factory swagger_server.wsgi:
the code in the app runs an ansible playbook.
When the run_playbook method of ansible is executed in the main thread of the uvicorn app, it works fine. The issue is only when the code is executed via swagger environment.
Example Code
No response
Python, Uvicorn & OS Version
Beta Was this translation helpful? Give feedback.
All reactions