Repository navigation
nmt: Fix wait_for_bootup race with a following heartbeat - #681
Open
SahilRajputdotexe wants to merge 1 commit into
Open
SahilRajputdotexe wants to merge 1 commit into
SahilRajputdotexe wants to merge 1 commit into
Conversation
wait_for_bootup() looked at _state_received after being notified, but a heartbeat handled before the waiting thread got to run had already overwritten the boot-up value, so the boot-up was missed and the call timed out. Remember the boot-up in its own flag and wait on that with wait_for(). Fixes canopen-python#560
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #560.
wait_for_bootup()checks_state_receivedafter it has been notified. If a heartbeat is handled before the waiting thread gets to run,_state_receivedhas already been overwritten with the new state, so the boot-up is missed and the call times out. That matches the log in the issue, where the boot-up is followed by a heartbeat within a millisecond. Moving the check inside the lock doesn't help, because the overwrite happens before the waiter gets the lock back.This keeps the boot-up in a separate flag that later heartbeats don't touch, and waits on it with
Condition.wait_for().The new test delivers a boot-up and a heartbeat while holding the condition lock, so the waiter can only run after both. It times out on master and passes with the change.
One small difference: the timeout is now exactly the value passed in. The old loop could wait about 0.1 s longer.