Skip to content

Commit

Permalink
5.6.2 (#2821)
Browse files Browse the repository at this point in the history
* Ensure `close` is called on the response body no matter what

Another fallout from #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.

* 5.6.2

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
  • Loading branch information
nateberkopec and byroot committed Feb 11, 2022
1 parent e0753de commit c6340d1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions History.md
@@ -1,3 +1,8 @@
## 5.6.2 / 2022-02-11

* Bugfix/Security
* Response body will always be `close`d. (GHSA-rmj8-8hhh-gv5h, related to [#2809])

## 5.6.1 / 2022-01-26

* Bugfixes
Expand Down
2 changes: 1 addition & 1 deletion lib/puma/const.rb
Expand Up @@ -100,7 +100,7 @@ class UnsupportedOption < RuntimeError
# too taxing on performance.
module Const

PUMA_VERSION = VERSION = "5.6.1".freeze
PUMA_VERSION = VERSION = "5.6.2".freeze
CODE_NAME = "Birdie's Version".freeze

PUMA_SERVER_STRING = ['puma', PUMA_VERSION, CODE_NAME].join(' ').freeze
Expand Down
15 changes: 10 additions & 5 deletions lib/puma/request.rb
Expand Up @@ -167,11 +167,16 @@ def handle_request(client, lines, requests)
end

ensure
uncork_socket io

body.close
client.tempfile.unlink if client.tempfile
res_body.close if res_body.respond_to? :close
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
Expand Down

0 comments on commit c6340d1

Please sign in to comment.