-
Notifications
You must be signed in to change notification settings - Fork 81
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
fix: check for nil before setting nil #128
Conversation
Codecov Report
@@ Coverage Diff @@
## master #128 +/- ##
==========================================
- Coverage 83.23% 82.49% -0.74%
==========================================
Files 8 8
Lines 495 497 +2
==========================================
- Hits 412 410 -2
- Misses 50 52 +2
- Partials 33 35 +2
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not fully understand how this would fix a race condition tbh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also confused at how this resolves race conditions. It's non-obvious (if at all), so should be documented in the code. Otherwise someone will go in and optimize those lines away without context, since there's no test to exercise the behavior in this repo.
The race happens when multiple routines calls SetCell. All of them write nil into the same slot. Writing nil is still writing and race detector complains. The race is fixed here because we check if the slot is nil already and those multiple routines only do reads of the slot now, which is race safe cc @adlerjohn, cc @liamsi |
Happy to document this in the code. |
Done |
Ran into the same issue while working on #123, can confirm it fixes the race condition |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK, but would like @liamsi to confirm
@liamsi, kind ping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/celestiaorg/rsmt2d/pull/128/files#r988034202
Right now the EDS does not have any guarantees regarding thread safety for reads and writes.
Can you please open an issue around that?
This change is motivated by the race conditions I observed. The roots are reset every time we do
SetCell
by setting nil. However, it causes race conditions between multipleSetCell
calls. This change fixes this and is tested against celestia-node