The Gin engine is initialized without a recovery middleware, causing connection drops on panic
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
Research direction
Start in internal/base/server/http.go at the gin.New() initialization, then read internal/base/handler/handler.go for the standard error response and logging conventions. Reproduce a handler panic as described and verify that the server returns the unified 500 JSON response with reason base.unknown while logging the panic and stack trace.
Written by the indexing model from the issue text.
Description
Describe the bug
In internal/base/server/http.go, the Gin engine is initialized via gin.New() without mounting a recovery middleware. When a panic occurs in any handler or middleware, the connection is dropped without returning a proper HTTP response to the client.
Current behavior
gin.New() (unlike gin.Default()) does not install any recovery middleware. When a panic propagates out of a handler:
- The Go runtime's
net/httpserver recovers per-connection, preventing the process from exiting. - But it closes the connection without writing any response body.
- The client sees a connection reset / EOF rather than a structured 5xx response.
- The panic is not logged through the project's logging facility (
pacman/log).
To Reproduce
This is a defensive coding issue rather than a directly triggerable bug. To verify the behavior, one can temporarily add panic("test") to any controller handler and observe that the client receives a connection error instead of an HTTP response.
Expected behavior
The server should return a unified 500 JSON response with reason: base.unknown, consistent with how other errors are handled in the project (see internal/base/handler/handler.go). The panic message and stack trace should be logged via the project's logger for diagnostics.
Additional context
I'd like to submit a PR to fix this by adding a middleware.Recovery() that:
- Logs the panic message and full stack trace via
log.Errorf+debug.Stack(). - Returns the standard error response using
handler.NewRespBody+TrMsgto stay consistent with the rest of the codebase. - Is mounted as the first middleware in
http.goso it covers all subsequent middleware and handlers.
- Dominant language
- Go
- Stars
- 15.7k
- Forks
- 1.4k
- Avg merge
- 5d 20h
- Merged PRs (30d)
- 6
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/answer
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Gravatar hash is computed from the un-lowercased email, so mixed-case accounts render an identicon Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
Difficulty 1/5 1-3 hours Newbie friendliness 75/100
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
enhancement needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
kind/cleanup
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
kubernetes-sigs/kueue#15947 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
sympozium-ai/sympozium#627 ·
-
priority: p3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
googleapis/librarian#7636 ·