Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Fixes job cancellation bug hidden behind race condition #1538

Merged
merged 5 commits into from
May 26, 2021

Conversation

izaaklauer
Copy link
Contributor

@izaaklauer izaaklauer commented May 26, 2021

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 before cancel() 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 to time.Time first does the trick.

Addresses one of the problems in #1521

With the race-loss logic still in place. If this works, the next commit will remove it.
@izaaklauer izaaklauer requested a review from a team May 26, 2021 02:57
@github-actions github-actions bot added the core label May 26, 2021
@izaaklauer izaaklauer changed the title Bug/job stream cancel race Job cancellation bug hidden behind race condition May 26, 2021
@izaaklauer izaaklauer changed the title Job cancellation bug hidden behind race condition Fixes job cancellation bug hidden behind race condition May 26, 2021
`==` does work here, but it also got us into this mess in the first place.
Copy link
Contributor

@evanphx evanphx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Copy link
Contributor

@krantzinator krantzinator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NICE

Copy link
Member

@briancain briancain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 🐛

@evanphx evanphx added this to the 0.4.x milestone May 26, 2021
@izaaklauer izaaklauer merged commit ab8a293 into main May 26, 2021
@izaaklauer izaaklauer deleted the bug/jobStreamCancelRace branch May 26, 2021 18:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants