Close instead of draining when a plug never honors Expect: 100-continue - #695
Open
tomciopp wants to merge 1 commit into
Open
Close instead of draining when a plug never honors Expect: 100-continue#695tomciopp wants to merge 1 commit into
tomciopp wants to merge 1 commit into
Conversation
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.
What happens today
A client sends
Expect: 100-continueand waits for the 100 before sending thebody. If the plug responds without ever reading the body (a 401, say), Bandit
never sends the 100, but after the response it still tries to drain the
request body to keep the connection alive. So the client is waiting on a 100
that will never come, and Bandit is waiting on a body that may never arrive.
The connection hangs until
read_timeout, and a request whose response wasalready delivered ends in a read-timeout error and an error log.
RFC9110§10.1.1 addresses exactly this case:
The change
When a final response is sent on HTTP/1.1 with the 100-continue expectation
still pending (and the plug didn't set its own
connectionheader), addconnection: close. The existing keepalive handling does the rest: it signalsthe close on the wire and skips the body drain.
An explicit
inform(conn, 100, ...)now also clears the pending expectation,since it unblocks the client the same way the implicit 100 does.
HTTP/2 needs no change: its
ensure_completedalready handles an unread bodywithout draining (RST_STREAM with NO_ERROR).
Test
POST with
expect: 100-continueand acontent-lengthbut no body; the plug401s without reading. Asserts the response carries
connection: close, theconnection closes, and the request's telemetry stop event has no error.
Before the fix: