Re-panic http.ErrAbortHandler in recovery middleware#4065
Merged
amirejaz merged 1 commit intostacklok:mainfrom Mar 11, 2026
Merged
Re-panic http.ErrAbortHandler in recovery middleware#4065amirejaz merged 1 commit intostacklok:mainfrom
amirejaz merged 1 commit intostacklok:mainfrom
Conversation
Go's httputil.ReverseProxy intentionally panics with http.ErrAbortHandler when a streaming response breaks mid-copy. Go's HTTP server has built-in handling for this sentinel: catch it silently, close the connection, move on. By intercepting ErrAbortHandler, the recovery middleware was: - Logging noisy stack traces for something that isn't a bug - Attempting to write http.Error() to an already-in-flight response - Preventing Go's HTTP server from cleanly aborting the connection This fix re-panics the sentinel, letting Go's HTTP server handle it as designed. Fixes stacklok#4064 Signed-off-by: Greg Katz <gkatz@indeed.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4065 +/- ##
==========================================
+ Coverage 68.63% 68.68% +0.04%
==========================================
Files 446 446
Lines 45435 45437 +2
==========================================
+ Hits 31185 31208 +23
+ Misses 11842 11820 -22
- Partials 2408 2409 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
jerm-dro
approved these changes
Mar 10, 2026
amirejaz
approved these changes
Mar 11, 2026
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
http.ErrAbortHandler. This is a sentinel that Go'shttputil.ReverseProxypanics with intentionally when a streaming response breaks mid-copy
(
reverseproxy.go:612). Go's HTTP server has built-in handling for it:catch it silently, close the connection, move on.
normal proxy behavior, attempts to write a 500 to an already-in-flight
response, and prevents Go's HTTP server from cleanly aborting the connection.
http.ErrAbortHandlerand re-panic it, letting Go's HTTP serverhandle it as designed.
Fixes #4064
Type of change
Test plan
task test)task lint-fix)Deployed a local ToolHive build with this fix and tested with mcp-optimizer
traffic. Before the fix: 150
abort Handlerpanic stack traces in the logover ~5 hours. After: zero.