diff --git a/changelogs/fragments/run_command_output_selector.yml b/changelogs/fragments/run_command_output_selector.yml new file mode 100644 index 00000000000..22f2c968448 --- /dev/null +++ b/changelogs/fragments/run_command_output_selector.yml @@ -0,0 +1,2 @@ +bugfixes: + - run_command - Fixed premature selector unregistration on empty read from stdout/stderr that caused truncated output or hangs in rare situations. diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index 5b5a05e8efc..116bfdec570 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -2090,7 +2090,7 @@ class AnsibleModule(object): stdout_changed = False for key, event in events: b_chunk = key.fileobj.read(32768) - if not b_chunk: + if not b_chunk and b_chunk is not None: selector.unregister(key.fileobj) elif key.fileobj == cmd.stdout: stdout += b_chunk