-
Notifications
You must be signed in to change notification settings - Fork 123
multi: fix race conditions and run unit tests with -race #890
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
Conversation
d38ac11 to
c69d9e4
Compare
bhandras
left a comment
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.
LGTM 🎉
| select { | ||
| case currentHeight := <-newBlockChan: | ||
| m.currentHeight = currentHeight | ||
| m.currentHeight.Store(currentHeight) |
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 think we should also initialize the current height by querying best height at the start on Run.
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.
Run already does this as soon as possible. Actually this is the only thing Run does - keeping currentHeight up-to-date.
staticaddr/address/manager.go
Outdated
|
|
||
| // Ensure that we have that we have a sane current block height. | ||
| if m.currentHeight == 0 { | ||
| if m.currentHeight.Load() == 0 { |
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.
This check could be removed if current height is correctly initialized.
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.
Run runs in background, so the caller doesn't know when Run has initialized currentHeight.
Additionally, it is better to double check even if it was initialized before, to detect a wrong order of methods called.
a123bc5 to
257b3db
Compare
| // NewManager creates a new address manager. | ||
| func NewManager(cfg *ManagerConfig) *Manager { | ||
| return &Manager{ | ||
| func NewManager(cfg *ManagerConfig, currentHeight int32) *Manager { |
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.
Nice, thanks!
sputn1ck
left a comment
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.
Thanks for the fix!
|
Rebased |
hieblmi
left a comment
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.
LGTM!
github.com/coreos/bbolt has race conditions: golang/go#54690
Make the current height an atomic variable in staticaddr/address/manager.go and in staticaddr/withdraw/manager.go. Removed the initiation height from staticaddr/deposit/manager.go (not needed).
The function used to call the method swapKit.swapInfo() which accessed many fields of the swapKit which may change in parallel by handlePaymentResult called by executeSwap (payInvoiceAsync is called in a goroutine). The fields are: cost, state, and update time.
If Run sets the current height field, it is technically a race between Run and other methods reading the field. Setting in New is a safer option. Removed a check that height is not 0 from static address manager.
7cc50fe to
2f2c5a3
Compare
Pull Request Checklist
release_notes.mdif your PR contains major features, breaking changes or bugfixes