fix: reset Http1Parser state in InitResponse to prevent false HTTP 200 on keep-alive reconnect#846
Merged
Merged
Conversation
…keep-alive reconnect
Copilot
AI
changed the title
[WIP] Fix misreported successful response on reused keep-alive connection
fix: reset Http1Parser state in InitResponse to prevent false HTTP 200 on keep-alive reconnect
Jul 9, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a client-side HTTP/1 parsing edge case on reused keep-alive connections where a zero-byte peer close could be misinterpreted as a completed response (defaulting to HTTP 200), bypassing the retry/error path. The change aligns InitResponse() (client-side) with InitRequest() (server-side) by fully resetting the parser state.
Changes:
- Reset
Http1Parser::statetoHP_START_REQ_OR_RESinsideInitResponse()after reinitializing the underlying C parser.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
On a reused keep-alive connection, if the peer closes without sending any bytes,
AsyncHttpClientincorrectly delivers a default-constructed HTTP 200 empty response instead of triggering a retry or error. The built-in retry mechanism is bypassed entirely.Root cause
Http1Parser::InitResponse()reset the underlying C parser and string buffers but not thestatemember. The previous response had setstate = HP_MESSAGE_COMPLETE. On reconnect,IsEof()→IsComplete()sees that stale value and returnstruewith zero bytes received, soonclosetakessuccessCallback()with a freshlyReset()response — whose defaultstatus_codeisHTTP_STATUS_OK.InitRequest()(server-side) already had the correct reset;InitResponse()lacked symmetry.Fix
virtual int InitResponse(HttpResponse* res) { res->Reset(); parsed = res; http_parser_init(&parser, HTTP_RESPONSE); + state = HP_START_REQ_OR_RES; url.clear();This makes a zero-byte peer close correctly take the error/retry path.