Bug Description
MemoryLock has a nil keys map. If a user writes var lock idempotency.MemoryLock without calling NewMemoryLock(), the first call to Lock() panics with "assignment to entry in nil map".
How to Reproduce
Steps to reproduce the behavior:
- Use
var lock idempotency.MemoryLock (zero value, no constructor)
- Call
lock.Lock("key", func() error { ... })
l.keys[key] = lock panics β nil map write
Affected Code
middleware/idempotency/locker.go:19-22:
type MemoryLock struct {
keys map[string]*countedLock // nil at zero value
mu sync.Mutex
}
Line 30:
l.keys[key] = lock // PANIC if l.keys is nil
Expected Behavior
Either lazy-initialize the map in Lock():
func (l *MemoryLock) Lock(key string, fn func() error) error {
l.mu.Lock()
if l.keys == nil {
l.keys = make(map[string]*countedLock)
}
// ...
}
Or make the struct unexported and only expose the constructor.
Fiber Version
v3 (latest main branch)
Bug Description
MemoryLockhas a nilkeysmap. If a user writesvar lock idempotency.MemoryLockwithout callingNewMemoryLock(), the first call toLock()panics with "assignment to entry in nil map".How to Reproduce
Steps to reproduce the behavior:
var lock idempotency.MemoryLock(zero value, no constructor)lock.Lock("key", func() error { ... })l.keys[key] = lockpanics β nil map writeAffected Code
middleware/idempotency/locker.go:19-22:Line 30:
Expected Behavior
Either lazy-initialize the map in
Lock():Or make the struct unexported and only expose the constructor.
Fiber Version
v3 (latest main branch)