Skip to content

🐛 fix: Remove unnecessary mutex locks and improve error handling#1974

Merged
mkmccarty merged 1 commit intomainfrom
mm-branch-1
Dec 23, 2025
Merged

🐛 fix: Remove unnecessary mutex locks and improve error handling#1974
mkmccarty merged 1 commit intomainfrom
mm-branch-1

Conversation

@mkmccarty
Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings December 23, 2025 02:12
@mkmccarty mkmccarty merged commit f7a0fde into main Dec 23, 2025
16 checks passed
@mkmccarty mkmccarty deleted the mm-branch-1 branch December 23, 2025 02:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to improve error handling for Discord API calls and remove mutex locks that were deemed unnecessary. However, the mutex lock removals introduce potential race conditions that need to be addressed.

  • Improved error handling for FollowupMessageCreate and ChannelMessageEditComplex calls by capturing and logging errors
  • Removed mutex locks around LastSaveTime field assignments in the save data flow
  • Changed Boost Menu visibility to always show regardless of contract state

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/boost/contract.go Added error handling for Discord API followup message creation and message edit operations, now properly capturing and logging errors instead of discarding them
src/boost/boost_datastore.go Removed mutex locks protecting LastSaveTime assignments during contract save operations
src/boost/boost_button_reactions.go Removed conditional check that previously hid the Boost Menu during signup state, menu now always displays

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

for _, c := range Contracts {
saveSqliteData(c)
c.mutex.Lock()
c.LastSaveTime = time.Now()
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

Removing the mutex lock around LastSaveTime assignment creates a potential race condition. This field is accessed without locking in the loop that iterates over all contracts. When multiple goroutines access different contracts or when one goroutine reads while another writes to the same contract's LastSaveTime, data races can occur. The Contract struct has a mutex field for thread safety, and this shared state modification should be protected.

Copilot uses AI. Check for mistakes.
Comment on lines +581 to +592
minValues := 0
out = append(out, discordgo.ActionsRow{
Components: []discordgo.MessageComponent{
discordgo.SelectMenu{
CustomID: "menu#" + contract.ContractHash,
Placeholder: "Boost Menu",
MinValues: &minValues,
MaxValues: 1,
Options: menuOptions,
},
})
}
},
})
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

Removing the conditional check if contract.State != ContractStateSignup changes the behavior to always show the Boost Menu, even during the signup phase. Previously, the menu was hidden during signup state. This appears to be an intentional behavior change, but if the menu contains actions that should not be available during signup (like the token-related menu options conditionally added on lines 486-537), this could lead to users accessing functionality in an inappropriate state. Consider whether all menu options are appropriate for the signup phase, or if certain options should be conditionally excluded based on contract state.

Copilot uses AI. Check for mistakes.

saveSqliteData(contract)
contract.mutex.Lock()
contract.LastSaveTime = time.Now()
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

Removing the mutex lock around LastSaveTime assignment creates a potential race condition. The LastSaveTime field is read without locking on lines 78 and 83 (via time.Since(contract.LastSaveTime)), and written without locking on line 90. This can lead to data races when multiple goroutines call saveData concurrently or when one goroutine reads while another writes. The Contract struct has a mutex field specifically for thread safety, and since LastSaveTime is part of the shared state, its access should be protected by the mutex.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants