Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/boost/boost_datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}()
}
Expand Down Expand Up @@ -136,6 +138,7 @@ func processSingleContractSave(contractHash string) {
contract.LastSaveTime = time.Now()
contract.mutex.Unlock()
Copy link

Copilot AI Jan 30, 2026

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.

Suggested change
contract.mutex.Unlock()

Copilot uses AI. Check for mistakes.
saveSqliteData(contract)
contract.mutex.Unlock()
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A double unlock is being performed on the contract mutex. The mutex is first unlocked at line 139, and then unlocked again at line 141. This will cause a panic at runtime with "sync: unlock of unlocked mutex". The second unlock at line 141 should be removed - the mutex is already properly unlocked at line 139 after setting LastSaveTime, and saveSqliteData does not require the mutex to be held.

Suggested change
contract.mutex.Unlock()

Copilot uses AI. Check for mistakes.
}

/*
Expand Down
Loading