diff --git a/changelogs/fragments/70023-results-type-filtering.yml b/changelogs/fragments/70023-results-type-filtering.yml new file mode 100644 index 00000000000..ece785139ba --- /dev/null +++ b/changelogs/fragments/70023-results-type-filtering.yml @@ -0,0 +1,5 @@ +bugfixes: +- Strategy - Ensure we only process expected types from the results queue + and produce warnings for any object we receive from the queue that doesn't + match our expectations. + (https://github.com/ansible/ansible/issues/70023) diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py index 93c80959562..1236986256c 100644 --- a/lib/ansible/plugins/strategy/__init__.py +++ b/lib/ansible/plugins/strategy/__init__.py @@ -100,16 +100,17 @@ def results_thread_main(strategy): result = strategy._final_q.get() if isinstance(result, StrategySentinel): break + elif isinstance(result, TaskResult): + with strategy._results_lock: + # only handlers have the listen attr, so this must be a handler + # we split up the results into two queues here to make sure + # handler and regular result processing don't cross wires + if 'listen' in result._task_fields: + strategy._handler_results.append(result) + else: + strategy._results.append(result) else: - strategy._results_lock.acquire() - # only handlers have the listen attr, so this must be a handler - # we split up the results into two queues here to make sure - # handler and regular result processing don't cross wires - if 'listen' in result._task_fields: - strategy._handler_results.append(result) - else: - strategy._results.append(result) - strategy._results_lock.release() + display.warning('Received an invalid object (%s) in the result queue: %r' % (type(result), result)) except (IOError, EOFError): break except Queue.Empty: