Skip to content

Commit

Permalink
Add support for deferred stop for graceful shutdown. (socketry#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Apr 23, 2024
1 parent 881eea9 commit cf5d5d4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/async/http/protocol/http1/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def each(task: Task.current)
return
end

begin
task.defer_stop do
# If a response was generated, send it:
if response
trailer = response.headers.trailer!
Expand Down
1 change: 1 addition & 0 deletions lib/async/http/protocol/http2/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def read_in_background(parent: Task.current)

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

# We don't need to defer stop here as this is already a transient task (ignores stop):
begin
while !self.closed?
self.consume_window
Expand Down
2 changes: 1 addition & 1 deletion lib/async/http/protocol/http2/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def each(task: Task.current)

@count += 1

begin
task.defer_stop do
response = yield(request)
rescue
# We need to close the stream if the user code blows up while generating a response:
Expand Down

0 comments on commit cf5d5d4

Please sign in to comment.