From 3a7030426efefe40bf9a7ba098cd99937b779a07 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Fri, 10 Oct 2025 21:02:50 +0200 Subject: [PATCH] Avoid losing data from events if multiple arrive at the same time. (#1158) (#1159) (#1160) (cherry picked from commit f7e976f3da97c73a402c5f35e793e470d6f71ca9) (cherry picked from commit db20b1876d905d0502a19d428789e78e3a13bec7) Co-authored-by: Felix Fontein --- changelogs/fragments/1158-select-fix.yml | 3 +++ plugins/connection/docker.py | 9 +++++++-- plugins/connection/nsenter.py | 9 +++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/1158-select-fix.yml diff --git a/changelogs/fragments/1158-select-fix.yml b/changelogs/fragments/1158-select-fix.yml new file mode 100644 index 00000000..83cc14cc --- /dev/null +++ b/changelogs/fragments/1158-select-fix.yml @@ -0,0 +1,3 @@ +bugfixes: + - "docker, nsenter connection plugins - fix handling of ``become`` plugin password prompt handling in case multiple events arrive at the same time + (https://github.com/ansible-collections/community.docker/pull/1158)." diff --git a/plugins/connection/docker.py b/plugins/connection/docker.py index 252f6451..5ff2f0b4 100644 --- a/plugins/connection/docker.py +++ b/plugins/connection/docker.py @@ -388,16 +388,21 @@ class Connection(ConnectionBase): stdout, stderr = p.communicate() raise AnsibleError('timeout waiting for privilege escalation password prompt:\n' + to_native(become_output)) + chunks = b"" for key, event in events: if key.fileobj == p.stdout: chunk = p.stdout.read() + if chunk: + chunks += chunk elif key.fileobj == p.stderr: chunk = p.stderr.read() + if chunk: + chunks += chunk - if not chunk: + if not chunks: stdout, stderr = p.communicate() raise AnsibleError('privilege output closed while waiting for password prompt:\n' + to_native(become_output)) - become_output += chunk + become_output += chunks finally: selector.close() diff --git a/plugins/connection/nsenter.py b/plugins/connection/nsenter.py index ccc660b9..9fc65490 100644 --- a/plugins/connection/nsenter.py +++ b/plugins/connection/nsenter.py @@ -170,16 +170,21 @@ class Connection(ConnectionBase): stdout, stderr = p.communicate() raise AnsibleError('timeout waiting for privilege escalation password prompt:\n' + to_native(become_output)) + chunks = b"" for key, event in events: if key.fileobj == p.stdout: chunk = p.stdout.read() + if chunk: + chunks += chunk elif key.fileobj == p.stderr: chunk = p.stderr.read() + if chunk: + chunks += chunk - if not chunk: + if not chunks: stdout, stderr = p.communicate() raise AnsibleError('privilege output closed while waiting for password prompt:\n' + to_native(become_output)) - become_output += chunk + become_output += chunks finally: selector.close()