Skip to content

Commit c6340d1

Browse files
nateberkopecbyroot
andauthored
5.6.2 (#2821)
* 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>
1 parent e0753de commit c6340d1

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

History.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 5.6.2 / 2022-02-11
2+
3+
* Bugfix/Security
4+
* Response body will always be `close`d. (GHSA-rmj8-8hhh-gv5h, related to [#2809])
5+
16
## 5.6.1 / 2022-01-26
27

38
* Bugfixes

lib/puma/const.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class UnsupportedOption < RuntimeError
100100
# too taxing on performance.
101101
module Const
102102

103-
PUMA_VERSION = VERSION = "5.6.1".freeze
103+
PUMA_VERSION = VERSION = "5.6.2".freeze
104104
CODE_NAME = "Birdie's Version".freeze
105105

106106
PUMA_SERVER_STRING = ['puma', PUMA_VERSION, CODE_NAME].join(' ').freeze

lib/puma/request.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,16 @@ def handle_request(client, lines, requests)
167167
end
168168

169169
ensure
170-
uncork_socket io
171-
172-
body.close
173-
client.tempfile.unlink if client.tempfile
174-
res_body.close if res_body.respond_to? :close
170+
begin
171+
uncork_socket io
172+
173+
body.close
174+
client.tempfile.unlink if client.tempfile
175+
ensure
176+
# Whatever happens, we MUST call `close` on the response body.
177+
# Otherwise Rack::BodyProxy callbacks may not fire and lead to various state leaks
178+
res_body.close if res_body.respond_to? :close
179+
end
175180

176181
after_reply.each { |o| o.call }
177182
end

0 commit comments

Comments
 (0)