fix(middleware): DefaultErrorHandler responds 503 instead of panicking on store error#266
Open
desperatee wants to merge 1 commit into
Open
fix(middleware): DefaultErrorHandler responds 503 instead of panicking on store error#266desperatee wants to merge 1 commit into
desperatee 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.
Summary
All three middleware adapters define the same broken default:
Panic-on-store-error has three downsides:
net/httprecovers the panic into a 500, but every recovered panic generates a stack trace and runs the full deferred chain. During a Redis outage, every request panics — turning a small store hiccup into a CPU + log spike. Operators see 500s with stack traces; the actual root cause (transient store error) is buried.Fix
Replace
panic(err)with:This is a sensible default. Operators who want fail-open or a custom status can override via
WithErrorHandler.The default response on store error changes from "500 + stack trace + log noise" (stdlib/gin) or "dropped connection" (fasthttp) to "503 + log line". Operators who were deliberately relying on the panic + recovery flow (unusual) need to add a custom
WithErrorHandlerto retain the old behavior.Design alternatives considered
_ = err): too dangerous. Rate limiting silently disabled is a much worse default than 503.LimiterErrorStrategyenum): more flexible but enlarges the API surface for an issue most users will never override.503-by-default + override-via-WithErrorHandler is the minimal change that fixes the panic while keeping the API surface stable.
Verification
go test -race ./...(minus Redis driver, which needs local Redis) is green. The PoC test panics on master and returns 503 after the patch.Severity
HIGH — production-grade DoS amplification: a transient store error becomes elevated CPU + log volume across the entire fleet. Affects all three adapters identically.