Skip to content

Commit 100ff2c

Browse files
authored
Add support for deferred stop for graceful shutdown. (#153)
1 parent f681cd4 commit 100ff2c

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

lib/async/http/protocol/http1/server.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def each(task: Task.current)
5555
return
5656
end
5757

58-
begin
58+
task.defer_stop do
5959
# If a response was generated, send it:
6060
if response
6161
trailer = response.headers.trailer!

lib/async/http/protocol/http2/connection.rb

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def read_in_background(parent: Task.current)
8989

9090
task.annotate("#{version} reading data for #{self.class}.")
9191

92+
# We don't need to defer stop here as this is already a transient task (ignores stop):
9293
begin
9394
while !self.closed?
9495
self.consume_window

lib/async/http/protocol/http2/server.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def each(task: Task.current)
5353

5454
@count += 1
5555

56-
begin
56+
task.defer_stop do
5757
response = yield(request)
5858
rescue
5959
# We need to close the stream if the user code blows up while generating a response:

0 commit comments

Comments
 (0)