Replace mustDiscard panic with error return (#1442)#2150
Open
Nicolas0315 wants to merge 1 commit intovalyala:masterfrom
Open
Replace mustDiscard panic with error return (#1442)#2150Nicolas0315 wants to merge 1 commit intovalyala:masterfrom
Nicolas0315 wants to merge 1 commit intovalyala:masterfrom
Conversation
mustDiscard() panics when bufio.Reader.Discard() fails, which crashes the entire server under high concurrency when connections time out during header reading. This panic cannot be recovered by any middleware since it occurs in the worker goroutine. Replace mustDiscard() with discardHeader() that returns an error, and propagate the error from all three call sites in header.go. This allows the server to gracefully handle connection timeouts instead of crashing. Fixes valyala#1442
Collaborator
|
This looks like an LLM finding a problem that doesn't exist. Do you have an example test case that triggers this bug? |
Contributor
|
@erikdubbelboer still a good idea to avoid calling panic in such a hot path. |
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.
Summary
Replace
mustDiscard()which panics onbufio.Reader.Discard()failure withdiscardHeader()that returns an error, preventing server crashes under high concurrency.Problem
Under high concurrency,
mustDiscard()inheader.gopanics when a connection times out during header reading:This panic occurs in the worker goroutine and cannot be recovered by any middleware (RouterPanic, Recovery, etc.), causing the entire server to crash.
Fix
mustDiscard()todiscardHeader()and return anerrorinstead of panickingheader.goto propagate the errorerror, so the change is straightforwardTesting
Fixes #1442