Skip to content

Fix race conditions when printing current status of tasks

Warren Gifford requested to merge mrn/fix-race-conditions into main

Created by: mrnugget

This fixes https://github.com/sourcegraph/sourcegraph/issues/16195 by doing two things:

  1. It threads every update and read of *TaskStatus in executor through a mutex to provide a consistent view of all []*TaskStatus. While we had a sync.Map in place it didn't protect us from race conditions, since we passed around pointers to TaskStatus freely: the executor goroutines would happily write to a *TaskStatus and the campaignProgressPrinter.PrintStatus would read []*TaskStatus while they're being updated. The sync.Map was useless in practice. So instead of that, I added a mutex that's used when updating a *TaskStatus and when reading all []*TaskStatus when printing the status.
  2. It uses a 1-capacity semaphore to control access to the campaignProgressPrinter through the PrintStatuses callback: only one execution at a time and if another execution is already in progress it returns.

Merge request reports

Loading