Skip to content

Commit a7eee15

Browse files
sivelchrismeyersfsunitzmahone
authored
[stable-2.19] Prevent IO capture hang/loss in basic.run_command (#85869) (#85891)
* Prevent run_command output truncation or hang In cases when the selector used to monitor stdout/stderr activates without data ready to read (a rare but normal condition), a read from a non-blocking FD can return `None`, which was being conflated with an empty read (EOF) condition. This caused the selector to be unregistered prematurely, sometimes resulting in truncated output or hangs. `None` read results are now excluded from EOF conditions. * add changelog --------- (cherry picked from commit 79ddee1) Co-authored-by: Chris Meyers <[email protected]> Co-authored-by: Matt Davis <[email protected]>
1 parent 4230329 commit a7eee15

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bugfixes:
2+
- run_command - Fixed premature selector unregistration on empty read from stdout/stderr that caused truncated output or hangs in rare situations.

lib/ansible/module_utils/basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2090,7 +2090,7 @@ def preexec():
20902090
stdout_changed = False
20912091
for key, event in events:
20922092
b_chunk = key.fileobj.read(32768)
2093-
if not b_chunk:
2093+
if not b_chunk and b_chunk is not None:
20942094
selector.unregister(key.fileobj)
20952095
elif key.fileobj == cmd.stdout:
20962096
stdout += b_chunk

0 commit comments

Comments
 (0)