diff --git a/lib/async/http/protocol/http1/server.rb b/lib/async/http/protocol/http1/server.rb index 23e1160b..901d25c3 100644 --- a/lib/async/http/protocol/http1/server.rb +++ b/lib/async/http/protocol/http1/server.rb @@ -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! diff --git a/lib/async/http/protocol/http2/connection.rb b/lib/async/http/protocol/http2/connection.rb index 9b26c9f2..0068ac23 100644 --- a/lib/async/http/protocol/http2/connection.rb +++ b/lib/async/http/protocol/http2/connection.rb @@ -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 diff --git a/lib/async/http/protocol/http2/server.rb b/lib/async/http/protocol/http2/server.rb index 73d7f833..907698ed 100644 --- a/lib/async/http/protocol/http2/server.rb +++ b/lib/async/http/protocol/http2/server.rb @@ -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: