Skip to content

Commit fc315cb

Browse files
Remove obsolete restart exception.
Assisted-By: devx/3236e566-7538-432e-a30a-2bdf37265ed4
1 parent 46fcc00 commit fc315cb

5 files changed

Lines changed: 10 additions & 22 deletions

File tree

lib/async/container/error.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@ def initialize
3131
end
3232
end
3333

34-
# Similar to {Interrupt}, but represents `SIGHUP`.
35-
class Restart < SignalException
36-
SIGHUP = Signal.list["HUP"]
37-
38-
# Create a new restart error.
39-
def initialize
40-
super(SIGHUP)
41-
end
42-
end
43-
4434
# Represents the error which occured when a container failed to start up correctly.
4535
class SetupError < Error
4636
# Create a new setup error.

lib/async/container/forked.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,8 @@ def self.fork(**options)
104104
# Fork from `Thread.new` so the child does not inherit the parent fiber scheduler or the current caller's fiber stack. Only this short-lived thread is copied into the child process:
105105
::Thread.new do
106106
::Process.fork do
107-
# We use `Thread.current.raise(...)` so that exceptions are filtered through `Thread.handle_interrupt` correctly.
108-
Signal.trap(:INT){::Thread.current.raise(Interrupt)}
109-
Signal.trap(:TERM){::Thread.current.raise(Interrupt)} # Same as SIGINT.
110-
Signal.trap(:HUP){::Thread.current.raise(Restart)}
111-
112-
# Reset `SignalException` delivery because CRuby inherits the `Thread.handle_interrupt` mask stack across `Thread.new`. Async deliberately masks signal exceptions, and the signal traps above should be delivered promptly:
113-
::Thread.handle_interrupt(SignalException => :immediate) do
107+
# Reset interrupt masking - `Exception` is a fast path:
108+
::Thread.handle_interrupt(Exception => :immediate) do
114109
yield Instance.for(process)
115110
rescue Interrupt
116111
# Graceful exit.

lib/async/container/threaded.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,6 @@ def kill!
211211
@thread.kill
212212
end
213213

214-
# Raise {Restart} in the child thread.
215-
def restart!
216-
@thread.raise(Restart)
217-
end
218-
219214
# Wait for the thread to exit and return he exit status.
220215
# @asynchronous This method may block.
221216
#

releases.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Use `async-signals` to coordinate controller signal traps while queueing signal events through the controller event loop.
66
- Require `async-signals` v0.6 so controller signal handling is implicit only when running on the main thread without an existing fiber scheduler, and loading `async-container` installs graceful default `SIGINT`/`SIGTERM` handling.
7+
- Remove the obsolete `Async::Container::Restart` signal exception.
78

89
## v0.37.0
910

test/async/container/policy.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,21 @@ def child_exit(container, child, status, name:, key:, **options)
254254
end.new
255255

256256
container = Async::Container.best_container_class.new(policy: stop_policy)
257+
trigger = IO.pipe
257258

258259
3.times do |i|
259260
container.spawn(name: "worker-#{i}") do |instance|
260261
instance.ready!
262+
263+
trigger.first.gets
261264
exit(1)
262265
end
263266
end
264267

268+
container.wait_until_ready
269+
270+
trigger.last.puts("exit")
271+
265272
container.wait
266273

267274
expect(stop_policy.stop_count).to be == 1

0 commit comments

Comments
 (0)