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..c9dd7a3a 100644 --- a/lib/async/http/protocol/http2/connection.rb +++ b/lib/async/http/protocol/http2/connection.rb @@ -89,7 +89,7 @@ def read_in_background(parent: Task.current) task.annotate("#{version} reading data for #{self.class}.") - begin + task.defer_stop do while !self.closed? self.consume_window self.read_frame 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: