1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00
puma--puma/lib/puma
Blake Williams b2283d8f25
Fix rack.after_reply exceptions breaking connections (#2861)
* Fix rack.after_reply exceptions breaking connections

Currently, when a `rack.after_reply` callable raises an exception we
attempt to handle it like other client errors by responding with an HTTP
500 response. This however doesn't work because `rack.after_reply`
callbacks are called after the response body has already been written to
the client.

This can cause issues with re-used connections. This is because 2 HTTP
responses are being returned for a single request. If a second HTTP
request is made before the error handling logic completes the timing can
line up causing the second HTTP response to be served a 500 from the
first HTTP requests `rack.after_reply` callbacks raising.

That may look roughly like:

1. Request 1 starts, opening a reusable TCP connection
2. Request 1 is written to and "completed"
3. Request 1 `rack.after_reply` callables are called
4. Request 2 starts, reusing the same TCP connection as request 1
5. `rack.after_reply` raises, calls `client_error` and serves a 500
   response
6. Request 2 receives the 500 response.

This is somewhat difficult to reproduce using HTTP clients since it's a
race condition whether or not the 500 is written at the "correct" time
or not.

To prevent this issue the `rack.after_reply` callables are now wrapped
in a begin/rescue/end block that rescues from `StandardError` and logs
instead of attempting to serve a 500 response.

* Assert against less specific exception
2022-04-17 10:21:36 -06:00
..
app Rename Puma::JSON to Puma::JSONSerialization (#2640) 2021-06-09 08:55:45 -06:00
cluster [WIP] Refactor: Split out LogWriter from Events (no logic change) (#2798) 2022-02-05 10:06:22 -07:00
launcher [WIP] Refactor: Split out LogWriter from Events (no logic change) (#2798) 2022-02-05 10:06:22 -07:00
minissl Fix missing log_writer 2022-02-09 14:41:55 -08:00
plugin
rack Add Rubocop for redundant returns 2021-06-10 12:28:35 -06:00
binder.rb Do not remove pre-existing socket after USR2+TERM (#2816) (#2817) 2022-02-20 07:27:57 -07:00
cli.rb [WIP] Refactor: Split out LogWriter from Events (no logic change) (#2798) 2022-02-05 10:06:22 -07:00
client.rb Merge pull request from GHSA-h99w-9q5r-gjq9 2022-03-30 08:06:46 -06:00
cluster.rb [WIP] Refactor: Split out LogWriter from Events (no logic change) (#2798) 2022-02-05 10:06:22 -07:00
commonlogger.rb
configuration.rb [WIP] Refactor: Split out LogWriter from Events (no logic change) (#2798) 2022-02-05 10:06:22 -07:00
const.rb 5.6.4 2022-03-30 07:27:53 -07:00
control_cli.rb [WIP] Refactor: Split out LogWriter from Events (no logic change) (#2798) 2022-02-05 10:06:22 -07:00
detect.rb Try to fix intermittent CI issues (#2739) 2021-10-31 12:06:58 +01:00
dsl.rb Clean up key/cert assignment in DSL (#2857) 2022-04-13 16:16:13 -06:00
error_logger.rb fix some spell errors (#2615) 2021-04-29 10:01:15 -06:00
events.rb [WIP] Refactor: Split out LogWriter from Events (no logic change) (#2798) 2022-02-05 10:06:22 -07:00
io_buffer.rb
jruby_restart.rb
json_serialization.rb Rename Puma::JSON to Puma::JSONSerialization (#2640) 2021-06-09 08:55:45 -06:00
launcher.rb [WIP] Refactor: Split out LogWriter from Events (no logic change) (#2798) 2022-02-05 10:06:22 -07:00
log_writer.rb [WIP] Refactor: Split out LogWriter from Events (no logic change) (#2798) 2022-02-05 10:06:22 -07:00
minissl.rb [jruby] support a truststore option (#2849) 2022-04-09 08:58:51 -06:00
null_io.rb Add #flush and #sync methods to Puma::NullIO (#2553) 2021-02-10 15:30:24 -07:00
plugin.rb Keep thread names under 15 characters (#2733) 2021-12-12 13:11:19 -07:00
queue_close.rb Refactor drain on shutdown (#2600) 2021-04-30 17:22:59 -05:00
rack_default.rb
reactor.rb Allow specifying the desired IO selector backend for nio4r (#2522) 2021-01-12 09:39:33 -07:00
request.rb Fix rack.after_reply exceptions breaking connections (#2861) 2022-04-17 10:21:36 -06:00
runner.rb [WIP] Refactor: Split out LogWriter from Events (no logic change) (#2798) 2022-02-05 10:06:22 -07:00
server.rb Merge pull request from GHSA-h99w-9q5r-gjq9 2022-03-30 08:06:46 -06:00
single.rb Server run thread safety fix [changelog skip] (#2435) 2020-10-20 07:26:16 -06:00
state_file.rb Fix Puma::StateFile#load returns empty string instead of nil (#2810) 2022-01-27 08:16:01 -06:00
systemd.rb [WIP] Refactor: Split out LogWriter from Events (no logic change) (#2798) 2022-02-05 10:06:22 -07:00
thread_pool.rb Bump RuboCop to work with newer Psych versions (#2783) 2021-12-31 14:18:16 +01:00
util.rb Escape SSL cert and filenames (#2855) 2022-04-09 09:02:39 -06:00