fix: avoid hanging on 101 switching protocol responses#2518
fix: avoid hanging on 101 switching protocol responses#2518arpitjain099 wants to merge 1 commit into
Conversation
Signed-off-by: Arpit Jain <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
Walkthrough
ChangesFix hang on 101 Switching Protocols / 304 Not Modified
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This fixes a hang when a target returns
101 Switching Protocolsand keeps the upgraded connection open.\n\nThe request path still installed a body-drain defer whenMaxResponseBodySizeToReadwas set. For upgrade responses, that defer could block forever onio.Copy(io.Discard, body)even though we intentionally skip body reads for websocket-style responses.\n\nI now skip that drain defer for the same status codes where body reads are skipped (101,304), and reuse that guard for the read branch too.\n\nI also added a regression test that stubs a101response with a body reader that never returns, and assertsDoreturns instead of hanging.\n\nFixes #2517\n\n### Verification\n-go test ./common/httpx -run "TestDoSwitchingProtocolsDoesNotHang|TestSetCustomHeaders|TestParseCustomCookies|TestHTTP11DisablesRetryableHTTP2FallbackClient|TestDefaultProtocolKeepsRetryableHTTP2FallbackClient" -count=1\n-go build ./cmd/httpx\n-go run ./cmd/httpx -u "http://cediplast.myqnapcloud.com:8085" -stats -v -timeout 5 -ncSummary by CodeRabbit