The Gin engine is initialized without a recovery middleware, causing connection drops on panic
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 75/100
Direzione di ricerca
Inizia da internal/base/server/http.go, all’inizializzazione di gin.New(), quindi leggi internal/base/handler/handler.go per le convenzioni relative alle risposte di errore standard e al logging. Riproduci un panic in un handler come descritto e verifica che il server restituisca la risposta JSON 500 unificata con reason base.unknown, registrando al contempo il panic e lo stack trace.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Go
- Stelle
- 15.7k
- Fork
- 1.4k
- Merge medio
- 5g 20h
- PR unite (30g)
- 6
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di apache/answer
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Gravatar hash is computed from the un-lowercased email, so mixed-case accounts render an identicon Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
-
🌐 Contribute a translation Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 75/100
-
apache/answer#1610 · 1 commento · 1 reazione · 1 assegnatario ·
Tutte le issue di apache/answer
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 84/100
-
enhancement needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
kind/cleanup
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
kubernetes-sigs/kueue#15947 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
sympozium-ai/sympozium#627 ·