1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Ensure close is called on the response body no matter what

Another fallout from https://github.com/puma/puma/pull/2809 is that
in some cases the `res_body.close` wasn't called because some previous code
raised.

For Rails apps it means CurrentAttributes and a few other important
states aren't reset properly.

This is being improved on the Rails side too, but I believe it would
be good to harden this on the puma side as well.
This commit is contained in:
Jean Boussier 2022-02-11 15:58:08 +01:00 committed by Nate Berkopec
parent 15dd1166ac
commit b70f451fe8
No known key found for this signature in database
GPG key ID: 19616755F4328D71

View file

@ -171,11 +171,16 @@ module Puma
end
ensure
begin
uncork_socket io
body.close
client.tempfile.unlink if client.tempfile
ensure
# Whatever happens, we MUST call `close` on the response body.
# Otherwise Rack::BodyProxy callbacks may not fire and lead to various state leaks
res_body.close if res_body.respond_to? :close
end
after_reply.each { |o| o.call }
end