This repository has been archived by the owner on Jan 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 330
Fixes job cancellation bug hidden behind race condition #1538
Merged
Conversation
This file contains 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
With the race-loss logic still in place. If this works, the next commit will remove it.
evanphx
suggested changes
May 26, 2021
`==` does work here, but it also got us into this mess in the first place.
evanphx
approved these changes
May 26, 2021
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.
krantzinator
approved these changes
May 26, 2021
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
briancain
approved these changes
May 26, 2021
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.
🔥 🐛
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixed the issue that caused these failures in CI:
This was a tricky one to track down. From the failed tests, we can see that the client was receiving duplicate cancellation events. I was able to replicate the failed test by adding a sleep here.
Here’s what I think is happening:
There are three goroutines at play here. One watching for DB changes and adding them to a channel (A), one listening for client events and adding them to a channel (B), and a big one pulling off the channels and doing work (C).
In the final phase of this test, the client sends a completion event onto the stream. B gets it, and passes it to C synchronously via an unbuffered channel. C handles it, which eventually results in a DB update on the job (marking its state as Success), and then the race begins.
On one side, B is going to return, which will trigger its deferred
cancel()
, which will cause C to return and the test to pass. On the other side, the update that C just made to the job is going to get picked up by A’s watchset, which will result in one more job update for C to process beforecancel()
comes around, which will exercise the bug.Generally, the memdb watchset path is slower than cancelling the context, so C never sees the final “Success” update to the job, and we don’t exercise the bug.
The bug is that we were treating the completion event as a cancellation event with an updated timestamp. It looks like
*timestamppb.Timestamp
’s aren’t nicely comparable with==
- they return not equal even if they have the same underlying time values. Converting them totime.Time
first does the trick.Addresses one of the problems in #1521