Fix double mutex unlock in concurrent contract save queue#2133
Merged
mkmccarty merged 3 commits intomm-branch-1from Jan 30, 2026
Merged
Fix double mutex unlock in concurrent contract save queue#2133mkmccarty merged 3 commits intomm-branch-1from
mkmccarty merged 3 commits intomm-branch-1from
Conversation
Co-authored-by: mkmccarty <57630+mkmccarty@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Update implementation based on feedback for contract save queue
Fix double mutex unlock in concurrent contract save queue
Jan 30, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a concurrency bug in saveData() where the “save queue full” path could fall through and unlock the same mutex twice.
Changes:
- Replace
breakwithcontinuein the queue-fulldefaultbranch to skip the outer unlock. - Explicitly unlock
saveQueueMutexbefore continuing to the next loop iteration.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
116
to
+119
| // Queue is full, skip this one (it will be retried in the next save cycle) | ||
| log.Printf("Save queue full, skipping contract: %s", contractHash) | ||
| // Do not mark as pending so it can be retried in a future save cycle | ||
| break | ||
| saveQueueMutex.Unlock() | ||
| continue |
There was a problem hiding this comment.
In the default branch, log.Printf runs while saveQueueMutex is held. Logging can block (I/O) and prolong mutex hold time, which may increase contention and delay the worker’s pendingSaves cleanup under load. Consider unlocking before logging (capture contractHash first) and keeping the locked section minimal; optionally rate-limit this message to avoid log spam when the queue is full.
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.
Addresses feedback from PR #2131 regarding a mutex double-unlock bug in
saveData().Issue
When the save queue is full,
breakonly exits theselectstatement, not theforloop, causing execution to fall through to a second unlock:Fix
Replace
breakwithcontinueto skip the second unlock when queue is full:default: saveQueueMutex.Unlock() continue // Skip to next loop iteration💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.