-
Notifications
You must be signed in to change notification settings - Fork 3
[WIP] Update concurrent contract save queue implementation based on feedback #2134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b385d84
2946cae
b209dca
6bcbb06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -41,13 +41,15 @@ func sqliteInit() { | |||
| func startSaveQueueWorker() { | ||||
| go func() { | ||||
| for contractHash := range saveQueue { | ||||
| // Mark as no longer pending | ||||
| // Process the actual save | ||||
| processSingleContractSave(contractHash) | ||||
|
|
||||
| // Mark as no longer pending after processing completes | ||||
| // This ensures that if the contract is modified during processing, | ||||
| // a new save request will be queued rather than being skipped | ||||
| saveQueueMutex.Lock() | ||||
| delete(pendingSaves, contractHash) | ||||
| saveQueueMutex.Unlock() | ||||
|
|
||||
| // Process the actual save | ||||
| processSingleContractSave(contractHash) | ||||
| } | ||||
| }() | ||||
| } | ||||
|
|
@@ -136,6 +138,7 @@ func processSingleContractSave(contractHash string) { | |||
| contract.LastSaveTime = time.Now() | ||||
| contract.mutex.Unlock() | ||||
| saveSqliteData(contract) | ||||
| contract.mutex.Unlock() | ||||
|
||||
| contract.mutex.Unlock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mutex is released before calling saveSqliteData, which means json.Marshal(contract) at line 217 occurs without mutex protection. This contradicts the PR description which states that mutex protection was added "during JSON marshaling in saveSqliteData()". If the contract fields are modified concurrently while json.Marshal is reading them, this could result in inconsistent data being saved or potential data races. Consider holding the mutex through the marshal operation, or document why concurrent reads during marshaling are safe in this context.