Bug Description
DefaultCtx.Done() returns nil, which blocks forever in any select statement. This means:
- Users cannot detect client disconnection via
ctx.Done()
- Libraries accepting
context.Context (database drivers, gRPC clients, HTTP clients) will never respect cancellation when passed Fiber's DefaultCtx
- The
context.Context interface contract is broken: Err() always returns nil, Deadline() always returns no deadline
How to Reproduce
Steps to reproduce the behavior:
- Create a handler that passes
c (the DefaultCtx) to a library expecting context.Context
- The client disconnects or a timeout fires
- The library never detects cancellation because
Done() returns nil
app.Get("/", func(c fiber.Ctx) error {
// This will never be cancelled even if the client disconnects
rows, err := db.QueryContext(c, "SELECT pg_sleep(60)")
// ...
})
Affected Code
Done() — ctx.go:168-170
func (*DefaultCtx) Done() <-chan struct{} {
return nil // blocks forever in select
}
Err() — ctx.go:176-178
func (*DefaultCtx) Err() error {
return nil // always returns nil, never reflects cancellation
}
Deadline() — ctx.go:156-158
func (*DefaultCtx) Deadline() (time.Time, bool) {
return time.Time{}, false // always returns no deadline
}
Contrast with fasthttp
Fasthttp's RequestCtx.Done() returns a server-level channel that at least signals server shutdown. Fiber's implementation is strictly less functional.
Expected Behavior
Done(), Err(), and Deadline() should delegate to the user context stored via SetContext():
func (c *DefaultCtx) Done() <-chan struct{} {
return c.Context().Done()
}
func (c *DefaultCtx) Err() error {
return c.Context().Err()
}
func (c *DefaultCtx) Deadline() (time.Time, bool) {
return c.Context().Deadline()
}
This would propagate cancellation from context.WithTimeout (set by the timeout middleware) or any user-set cancelable context. When no context is set, c.Context() returns context.Background() whose Done() is nil — matching current behavior.
Fiber Version
v3 (latest main branch)
Bug Description
DefaultCtx.Done()returnsnil, which blocks forever in anyselectstatement. This means:ctx.Done()context.Context(database drivers, gRPC clients, HTTP clients) will never respect cancellation when passed Fiber'sDefaultCtxcontext.Contextinterface contract is broken:Err()always returnsnil,Deadline()always returns no deadlineHow to Reproduce
Steps to reproduce the behavior:
c(theDefaultCtx) to a library expectingcontext.ContextDone()returnsnilAffected Code
Done()—ctx.go:168-170Err()—ctx.go:176-178Deadline()—ctx.go:156-158Contrast with fasthttp
Fasthttp's
RequestCtx.Done()returns a server-level channel that at least signals server shutdown. Fiber's implementation is strictly less functional.Expected Behavior
Done(),Err(), andDeadline()should delegate to the user context stored viaSetContext():This would propagate cancellation from
context.WithTimeout(set by the timeout middleware) or any user-set cancelable context. When no context is set,c.Context()returnscontext.Background()whoseDone()isnil— matching current behavior.Fiber Version
v3 (latest main branch)