Fix race conditions when printing current status of tasks#399
Merged
Conversation
eseliger
approved these changes
Nov 30, 2020
eseliger
left a comment
Member
There was a problem hiding this comment.
Code LGTM, I trust you that it fixes the underlying issue :)
LawnGnome
approved these changes
Dec 1, 2020
LawnGnome
left a comment
Contributor
There was a problem hiding this comment.
LGTM. Thanks for fixing this bug! (I'll spare us all the Rust evangelism here.)
Contributor
Author
I know :| But to be fair to Go, what we're doing here is communicating between two parts by sharing memory, instead of sharing by communicating. (This is orthogonal to Rust's memory checks that would've probably avoided this, but a thought I had yesterday) |
scjohns
pushed a commit
that referenced
this pull request
Apr 24, 2023
* Replace sync.Map with locked access around TaskStatuses * Avoid PrintStatuses being called concurrently * Add changelog entry
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.
This fixes https://github.com/sourcegraph/sourcegraph/issues/16195 by doing two things:
*TaskStatusinexecutorthrough a mutex to provide a consistent view of all[]*TaskStatus. While we had async.Mapin place it didn't protect us from race conditions, since we passed around pointers toTaskStatusfreely: theexecutorgoroutines would happily write to a*TaskStatusand thecampaignProgressPrinter.PrintStatuswould read[]*TaskStatuswhile they're being updated. Thesync.Mapwas useless in practice. So instead of that, I added a mutex that's used when updating a*TaskStatusand when reading all[]*TaskStatuswhen printing the status.campaignProgressPrinterthrough thePrintStatusescallback: only one execution at a time and if another execution is already in progress it returns.