You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
timeoutMiddleware drops the handler's panic stack, so logged panics always point at middleware.go #2904
I confirm this is a bug with Supabase, not with my own application.
I confirm I have searched the Docs, GitHub Discussions, and Discord.
Describe the bug
When a handler panics behind timeoutMiddleware, the stack that gets logged never shows where the panic actually happened. It always points at the panic(p) line inside timeoutMiddleware itself.
The handler runs in its own goroutine. Its deferred recover() sends only the panic value over panicChan, and the serving goroutine re-panics with panic(p). recoverer then logs debug.Stack(), which is the stack of that re-panic, not of the handler. The original stack is gone by then.
This is why the traces in #2233 and #2268 both end at middleware.go (:392 and :431 in those builds are the panic(p) line) and say nothing about the code that failed. In #2268 the actual cause was eventually found by reading code, and in #2508 the trace was read as a nil snapHeader inside the middleware, which couldn't be reproduced.
To Reproduce
Mount any handler that panics, e.g. panic("boom"), behind recoverer and timeoutMiddleware, the same way NewAPIWithVersion does.
Send a request to it.
Look at the stack field of the logged panic: it has timeoutMiddleware.func... at the top and no frame from the handler.
I have a small test that does this against master (d7955e9) and checks that the logged stack contains the handler's function name. It fails on master.
Expected behavior
The logged stack points at the line in the handler that panicked.
A minimal fix: in the handler goroutine, capture debug.Stack() in the deferred recover and send it together with the value (e.g. a small handlerPanic{value, stack} type). recoverer unwraps it and logs the original stack. Happy to open a PR with the test if this approach works for you.
Activity
aniketatgithub commentedon Nov 6, 2026
I'd like to work on this. The panic stack loss is in timeoutMiddleware's recover and re-panic path; I'll open a PR with a fix and a regression test.