Avoid losing data from events if multiple arrive at the same time. (#1158) (#1159)

(cherry picked from commit f7e976f3da)
This commit is contained in:
Felix Fontein 2025-10-10 20:28:27 +02:00 committed by GitHub
parent 3b0ab3bd8b
commit db20b1876d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 4 deletions

View File

@ -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)."

View File

@ -378,16 +378,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()

View File

@ -166,16 +166,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()