From aac47b5b220c8d686b69020fc1ef9ffc6d7f2bbf Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Tue, 31 Aug 2021 12:37:40 -0400 Subject: [PATCH 1/2] Catch exceptions from Ansible::Runner.run* --- app/models/manageiq/providers/ansible_runner_workflow.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/manageiq/providers/ansible_runner_workflow.rb b/app/models/manageiq/providers/ansible_runner_workflow.rb index 521610fe4cf..4fbd150b006 100644 --- a/app/models/manageiq/providers/ansible_runner_workflow.rb +++ b/app/models/manageiq/providers/ansible_runner_workflow.rb @@ -50,6 +50,8 @@ def execute route_signal(:poll_runner) end + rescue => err + route_signal(:abort, "Failed to run ansible #{execution_type}: #{err}", "error") end def poll_runner From 34a688eb80b903aab09e6bfd5f0aa245ff7de8e6 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Tue, 31 Aug 2021 12:38:02 -0400 Subject: [PATCH 2/2] Catch ArgumentError from Listen#start --- lib/ansible/runner.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/ansible/runner.rb b/lib/ansible/runner.rb index 73a5ddad931..284f9c97ab5 100644 --- a/lib/ansible/runner.rb +++ b/lib/ansible/runner.rb @@ -371,7 +371,15 @@ def wait_for(path, timeout: 10.seconds) path_created.set if added.include?(path) || modified.include?(path) end - thread = Thread.new { listener.start } + thread = Thread.new do + listener.start + rescue ArgumentError => err + # If the main thread raises an exception immediately it is possible + # for the ensure block to call `listener.stop` before this thread + # begins its execution resulting in an ArgumentError due to the state + # being `:stopped` + raise unless err.message.include?("cannot start from state :stopped") + end begin res = yield