Skip to content

fix(BRIDGE-632): add lock to snapMsgList idx map - #496

Open
annatar wants to merge 1 commit into
devfrom
fix/bridge-632
Open

annatar wants to merge 1 commit into
devfrom
fix/bridge-632

Conversation

@annatar

@annatar annatar commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread internal/state/snapshot_messages.go Outdated
Comment on lines +94 to +97
func (list *snapMsgList) remove(msgID imap.InternalMessageID) bool {
list.lock.Lock()
defer list.lock.Unlock()

@ElectroNafta ElectroNafta Sep 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's have a nice wrapper around this so we never forget to unlock things (not just here; but unify the usage)

func (l *snapMsgList) withLock(fn func ()) {
   l.lock.Lock()
   defer l.lock.Unlock()
    fn ()
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

isn't this overcomplicating it, there are 5 calls to list.idx

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd enforce the convention to always use that instead of bare lock calls. + better DRY

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah but we don't want the whole function to be locked in all cases + only Read lock in some

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

  • there would be a need to create example updateUnsafe + update which update just calls withLock(updateUnsafe(...)), which is a lot of extra code for again 5 calls to this map

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