Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rack.after_reply exceptions breaking connections #2861

Merged
merged 2 commits into from Apr 17, 2022

Commits on Apr 16, 2022

  1. 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.
    BlakeWilliams committed Apr 16, 2022
    Configuration menu
    Copy the full SHA
    fb734cb View commit details
    Browse the repository at this point in the history

Commits on Apr 17, 2022

  1. Configuration menu
    Copy the full SHA
    d044ed2 View commit details
    Browse the repository at this point in the history