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

fix: check for nil before setting nil #128

Merged
merged 2 commits into from
Oct 5, 2022
Merged

fix: check for nil before setting nil #128

merged 2 commits into from
Oct 5, 2022

Conversation

Wondertan
Copy link
Member

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 multiple SetCell calls. This change fixes this and is tested against celestia-node

@Wondertan Wondertan added the bug Something isn't working label Sep 28, 2022
@Wondertan Wondertan self-assigned this Sep 28, 2022
@codecov
Copy link

codecov bot commented Sep 28, 2022

Codecov Report

Merging #128 (861ed5d) into master (33a5763) will decrease coverage by 0.73%.
The diff coverage is 0.00%.

❗ Current head 861ed5d differs from pull request most recent head ed5b81e. Consider uploading reports for the commit ed5b81e to get more accurate results

@@            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     
Impacted Files Coverage Δ
datasquare.go 90.78% <0.00%> (-2.55%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@liamsi liamsi left a 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

Copy link
Member

@adlerjohn adlerjohn left a 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.

@Wondertan
Copy link
Member Author

Wondertan commented Sep 28, 2022

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

@Wondertan
Copy link
Member Author

Happy to document this in the code.

@Wondertan
Copy link
Member Author

Done

@rahulghangas rahulghangas mentioned this pull request Sep 28, 2022
1 task
@rahulghangas
Copy link
Contributor

Ran into the same issue while working on #123, can confirm it fixes the race condition

Copy link
Member

@adlerjohn adlerjohn left a 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

@Wondertan
Copy link
Member Author

@liamsi, kind ping

Copy link
Member

@liamsi liamsi left a 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?

@Wondertan
Copy link
Member Author

@liamsi, #135

@Wondertan Wondertan merged commit 21e6086 into master Oct 5, 2022
@Wondertan Wondertan deleted the fix-reset branch October 5, 2022 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants