Bug Description
Session methods that perform storage I/O (Destroy, Regenerate, Reset, Save) do not accept a context.Context parameter. They use an internal fiber.Ctx field which has no-op cancellation (Done() returns nil). Users have no way to pass a properly-scoped context for cancellation or timeout control.
How to Reproduce
Steps to reproduce the behavior:
- Get a session in a handler:
sess, _ := session.Get(c)
- Call
sess.Destroy() β this performs Storage.DeleteWithContext() internally
- The storage backend is slow (e.g., Redis over a slow network)
- There is no way to set a timeout or cancellation on this operation
- Even if the client disconnects, the storage I/O runs to completion
Affected Methods
| Method |
Line |
I/O Operation |
Destroy() |
session/session.go:187 |
Storage.DeleteWithContext(ctx, s.id) |
Regenerate() |
session/session.go:220 |
Storage.DeleteWithContext(ctx, s.id) |
Reset() |
session/session.go:247 |
Storage.DeleteWithContext(ctx, s.id) |
Save() / saveSession() |
session/session.go:294,311 |
Storage.SetWithContext(ctx, s.id, ...) |
All four use this fallback pattern:
var ctx context.Context = s.ctx
if ctx == nil {
ctx = context.Background()
}
When s.ctx is nil (after Release() or when created via Store.GetByID()), the fallback is context.Background() β uncancellable.
Expected Behavior
Add *WithContext variants, mirroring the SharedState pattern:
func (s *Session) DestroyWithContext(ctx context.Context) error { ... }
func (s *Session) RegenerateWithContext(ctx context.Context) error { ... }
func (s *Session) ResetWithContext(ctx context.Context) error { ... }
func (s *Session) SaveWithContext(ctx context.Context) error { ... }
The existing methods can delegate to the *WithContext variants with the stored s.ctx as fallback.
Related
Fiber Version
v3 (latest main branch)
Bug Description
Session methods that perform storage I/O (
Destroy,Regenerate,Reset,Save) do not accept acontext.Contextparameter. They use an internalfiber.Ctxfield which has no-op cancellation (Done()returnsnil). Users have no way to pass a properly-scoped context for cancellation or timeout control.How to Reproduce
Steps to reproduce the behavior:
sess, _ := session.Get(c)sess.Destroy()β this performsStorage.DeleteWithContext()internallyAffected Methods
Destroy()session/session.go:187Storage.DeleteWithContext(ctx, s.id)Regenerate()session/session.go:220Storage.DeleteWithContext(ctx, s.id)Reset()session/session.go:247Storage.DeleteWithContext(ctx, s.id)Save()/saveSession()session/session.go:294,311Storage.SetWithContext(ctx, s.id, ...)All four use this fallback pattern:
When
s.ctxis nil (afterRelease()or when created viaStore.GetByID()), the fallback iscontext.Background()β uncancellable.Expected Behavior
Add
*WithContextvariants, mirroring theSharedStatepattern:The existing methods can delegate to the
*WithContextvariants with the storeds.ctxas fallback.Related
shared_state.goalready has*WithContextvariants for all 13 convenience methodsFiber Version
v3 (latest main branch)