🐛 bug: Make idempotency MemoryLock safe for zero-value use#4371
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix panic on zero-value usage of MemoryLock
Make idempotency MemoryLock safe for zero-value use
May 28, 2026
gaby
approved these changes
May 28, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes middleware/idempotency.MemoryLock safe to use as a zero value by lazily initializing its internal key map on first lock acquisition.
Changes:
- Lazily initializes
MemoryLock.keysinsideLock(). - Adds regression coverage for zero-value
MemoryLocklock/unlock behavior and missing-key unlock after initialization.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
middleware/idempotency/locker.go |
Adds lazy map initialization to support zero-value MemoryLock usage. |
middleware/idempotency/locker_test.go |
Adds a zero-value regression subtest for MemoryLock. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4371 +/- ##
==========================================
- Coverage 91.39% 91.35% -0.05%
==========================================
Files 132 132
Lines 13098 13100 +2
==========================================
- Hits 11971 11967 -4
- Misses 710 715 +5
- Partials 417 418 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ReneWerner87
approved these changes
May 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
idempotency.MemoryLockpanicked when used as a zero value because its internalkeysmap was nil on firstLock(). This change makes zero-value usage safe without changing the existing constructor-based path.Zero-value safety
MemoryLock.keysinsideLock()before first use.Regression coverage
var l idempotency.MemoryLockLock()/Unlock()Usage example
Changes introduced
MemoryLockno longer panics on first use.Type of change
Please delete options that are not relevant.
Checklist
Before you submit your pull request, please make sure you meet these requirements:
/docs/directory for Fiber's documentation.Commit formatting
Please use emojis in commit messages for an easy way to identify the purpose or intention of a commit. Check out the emoji cheatsheet here: CONTRIBUTING.md