Skip to content

Commit 9986da8

Browse files
Use graceful defaults for controller interrupts.
Assisted-By: devx/3236e566-7538-432e-a30a-2bdf37265ed4
1 parent 94e25a3 commit 9986da8

2 files changed

Lines changed: 1 addition & 46 deletions

File tree

lib/async/container/controller.rb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
require "async"
1414
require "async/signals"
15+
require "async/signals/graceful"
1516

1617
module Async
1718
module Container
@@ -50,8 +51,6 @@ def call
5051
end
5152

5253
SIGHUP = Signal.list["HUP"]
53-
SIGINT = Signal.list["INT"]
54-
SIGTERM = Signal.list["TERM"]
5554
SIGUSR1 = Signal.list["USR1"]
5655
SIGUSR2 = Signal.list["USR2"]
5756

@@ -69,14 +68,6 @@ def initialize(notify: Notify.open!, container_class: Container, graceful_stop:
6968
# Serializes lifecycle transitions such as start, restart and reload. `Container#stop` (which can also take time) is performed outside this guard, so that live container events are not blocked by the stop operation (e.g. restarting).
7069
@guard = ::Thread::Mutex.new
7170

72-
@signals.trap(SIGINT) do |_signal, context|
73-
context.raise(Interrupt)
74-
end
75-
76-
@signals.trap(SIGTERM) do |_signal, context|
77-
context.raise(Interrupt)
78-
end
79-
8071
self.trap(SIGHUP) do
8172
self.restart
8273
rescue SetupError => error

test/async/container/controller.rb

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -261,42 +261,6 @@ def controller.setup(container)
261261
expect(handlers.fetch("USR2")).to be_nil
262262
end
263263

264-
it "raises interrupt for SIGINT" do
265-
context = Object.new
266-
267-
def context.raise(exception)
268-
@exception = exception
269-
end
270-
271-
def context.exception
272-
@exception
273-
end
274-
275-
handlers = controller.instance_variable_get(:@signals).to_h
276-
277-
handlers.fetch("INT").call(Async::Container::Controller::SIGINT, context)
278-
279-
expect(context.exception).to be == Interrupt
280-
end
281-
282-
it "raises interrupt for SIGTERM" do
283-
context = Object.new
284-
285-
def context.raise(exception)
286-
@exception = exception
287-
end
288-
289-
def context.exception
290-
@exception
291-
end
292-
293-
handlers = controller.instance_variable_get(:@signals).to_h
294-
295-
handlers.fetch("TERM").call(Async::Container::Controller::SIGTERM, context)
296-
297-
expect(context.exception).to be == Interrupt
298-
end
299-
300264
it "queues trapped signal events" do
301265
controller = Async::Container::Controller.new(notify: nil)
302266
applied = false

0 commit comments

Comments
 (0)