Close connection on 5xx error to avoid leaking exchanges on slow uploads#16
Closed
samberic wants to merge 1 commit into
Closed
Close connection on 5xx error to avoid leaking exchanges on slow uploads#16samberic wants to merge 1 commit into
samberic wants to merge 1 commit into
Conversation
When a target failed before sending a response (target died or timed out), murp set a 500/504 status, wrote the body, and called asyncHandle.complete(). If the client was still uploading the request body at that point (e.g. a slow or large PUT), the request stayed in RECEIVING_BODY and never reached an end state. MuServer only ends an exchange once BOTH the request and response are in an end state, so the exchange stayed IN_PROGRESS and the request lingered in stats().activeRequests() until the client finished uploading - which for long-running uploads could be hours or days. We observed many such PUTs stuck for days. Setting "Connection: close" on the error response makes MuServer's HttpServerKeepAliveHandler close the channel once the response is sent. That triggers onConnectionEnded -> request.onCancelled(CLIENT_DISCONNECTED), moving the request to ERRORED so the exchange completes and is released. This mirrors what MuServer itself does for unrecoverable HTTP/1.1 errors in HttpExchange.onException. The sibling branch (target dies after the response has started streaming) already calls asyncHandle.complete(throwable), which routes through onException and cancels the request, so it does not leak and needs no change.
Contributor
|
Inspired by the insight of this pull request, a separate fix has been made that properly consumes and discards client request bodies when the target request has a transport failure, such that the client can have a valid http 502 response. Using version 1.2.x or later. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a target failed before sending a response (target died or timed out), murp set a 500/504 status, wrote the body, and called asyncHandle.complete(). If the client was still uploading the request body at that point (e.g. a slow or large PUT), the request stayed in RECEIVING_BODY and never reached an end state.
MuServer only ends an exchange once BOTH the request and response are in an end state, so the exchange stayed IN_PROGRESS and the request lingered in stats().activeRequests() until the client finished uploading - which for long-running uploads could be hours or days. We observed many such PUTs stuck for days.
Setting "Connection: close" on the error response makes MuServer's HttpServerKeepAliveHandler close the channel once the response is sent. That triggers onConnectionEnded -> request.onCancelled(CLIENT_DISCONNECTED), moving the request to ERRORED so the exchange completes and is released. This mirrors what MuServer itself does for unrecoverable HTTP/1.1 errors in HttpExchange.onException.
The sibling branch (target dies after the response has started streaming) already calls asyncHandle.complete(throwable), which routes through onException and cancels the request, so it does not leak and needs no change.