lib/async/http/protocol/http1/server.rb in async-http-0.70.0 vs lib/async/http/protocol/http1/server.rb in async-http-0.71.0

- old
+ new

@@ -5,22 +5,24 @@ # Copyright, 2020, by Igor Sidorov. # Copyright, 2023, by Thomas Morgan. # Copyright, 2024, by Anton Zhuravsky. require_relative 'connection' +require 'console/event/failure' module Async module HTTP module Protocol module HTTP1 class Server < Connection def fail_request(status) @persistent = false write_response(@version, status, {}) write_body(@version, nil) - rescue Errno::ECONNRESET, Errno::EPIPE - # Nothing we can do... + rescue => error + # At this point, there is very little we can do to recover: + Console::Event::Failure.for(error).emit(self, "Failed to write failure response.", severity: :debug) end def next_request # The default is true. return unless @persistent @@ -31,16 +33,12 @@ unless persistent?(request.version, request.method, request.headers) @persistent = false end return request - rescue Async::TimeoutError - # For an interesting discussion about this behaviour, see https://trac.nginx.org/nginx/ticket/1005 - # If you enable this, you will see some spec failures... - # fail_request(408) - raise - rescue + rescue ::Protocol::HTTP1::BadRequest fail_request(400) + # Conceivably we could retry here, but we don't really know how bad the error is, so it's better to just fail: raise end # Server loop. def each(task: Task.current)