Skip to content

Commit 69bfd47

Browse files
macournoyerioquatix
authored andcommitted
Move error handling to ensure loop continues after child process management (#46)
1 parent 2826b6e commit 69bfd47

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/async/container/generic.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ def spawn(name: nil, restart: false, key: nil, health_check_timeout: nil, &block
191191
age_clock = state[:age] = Clock.start
192192
end
193193

194+
status = nil
195+
194196
begin
195197
status = @group.wait_for(child) do |message|
196198
case message
@@ -203,11 +205,13 @@ def spawn(name: nil, restart: false, key: nil, health_check_timeout: nil, &block
203205
age_clock&.reset!
204206
end
205207
end
208+
rescue => error
209+
Console.error(self, "Error during child process management!", exception: error, running: @running)
206210
ensure
207211
delete(key, child)
208212
end
209213

210-
if status.success?
214+
if status&.success?
211215
Console.info(self, "Child exited successfully.", status: status, running: @running)
212216
else
213217
@statistics.failure!
@@ -220,9 +224,6 @@ def spawn(name: nil, restart: false, key: nil, health_check_timeout: nil, &block
220224
break
221225
end
222226
end
223-
rescue => error
224-
Console.error(self, "Failure during child process management!", exception: error, running: @running)
225-
raise
226227
ensure
227228
Console.info(self, "Child process management loop exited.", running: @running)
228229
end.resume

releases.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Releases
22

3+
## Unreleased
4+
5+
- Make the child handling more robust in the face of exceptions.
6+
37
## v0.27.4
48

59
- Fix race condition where `wait_for` could modify `@running` while it was being iterated over (`each_value`) during health checks.

0 commit comments

Comments
 (0)