Skip to content
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

hotfix(exporter): fix data race #1883

Draft
wants to merge 5 commits into
base: stage
Choose a base branch
from
Draft

Conversation

olegshmuelov
Copy link
Contributor

No description provided.

@nkryuchkov nkryuchkov changed the title Exporter race fix hotfix(exporter): fix data race Nov 26, 2024
c.committeesObserversMutex.Lock()
defer c.committeesObserversMutex.Unlock()

if msg.MsgType == spectypes.SSVConsensusMsgType {
// Check if the observer already exists
existingObserver := c.committeesObservers.Get(ssvMsg.GetID())
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't ttlcache already thread safe? why we need the mutex here then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without the mutex, there’s a risk of race conditions where multiple goroutines might attempt to create and set the same observer simultaneously.

Copy link
Contributor

Choose a reason for hiding this comment

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

this can be also solved by the cache's GetOrSet func, but involves creating the observer each time and sometimes for nothing. though it will be GC'd quickly if not used, there is no goroutine in the creation.

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