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

chain head listener: Fix race condition #2366

Merged
merged 1 commit into from
Apr 12, 2021
Merged

Conversation

leoyvens
Copy link
Collaborator

This is a correction to #2365. There is a race condition in the else branch where the watcher could be overwritten, and a subscriber might end up with a receiver that has no sender and would error.

This keeps it simple by using a Mutex, and switching to a sync Mutex since that's what tokio recommends for short critical sections.

@leoyvens leoyvens requested a review from lutter April 11, 2021 15:26
@evaporei
Copy link
Contributor

evaporei commented Apr 12, 2021

I read all of the code and it seems fine 🙂
I just have one question, why wasn't RwLock working before? 🤔

@leoyvens
Copy link
Collaborator Author

leoyvens commented Apr 12, 2021

@otaviopace We need to have a complete lock even for the read because otherwise two threads can read, not find an entry, and simultaneously insert a new watcher, and one will overwrite the other.

@leoyvens leoyvens merged commit 1fde437 into master Apr 12, 2021
@leoyvens leoyvens deleted the leo/fix-race-condition branch April 12, 2021 13:33
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