Skip to content

Commit

Permalink
Merge pull request #15661 from hpidcock/fix-data-race-getosfromseries
Browse files Browse the repository at this point in the history
#15661

GetOSFromSeries was making reads (calling getOSFromSeries) outside the scope of a mutex lock.

## QA steps

Run tests with -race

## Documentation changes

N/A

## Bug reference

https://jenkins.juju.canonical.com/job/unit-tests-race-amd64/1150/consoleText
  • Loading branch information
jujubot committed May 26, 2023
2 parents 686b6f2 + 6841e1b commit f639f09
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions core/series/supportedseries.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,16 @@ func GetOSFromSeries(series string) (coreos.OSType, error) {
if series == "" {
return coreos.Unknown, errors.NotValidf("series %q", series)
}

seriesVersionsMutex.Lock()
defer seriesVersionsMutex.Unlock()

seriesName := SeriesName(series)
osType, err := getOSFromSeries(seriesName)
if err == nil {
return osType, nil
}

seriesVersionsMutex.Lock()
defer seriesVersionsMutex.Unlock()

updateSeriesVersionsOnce()
return getOSFromSeries(seriesName)
}
Expand Down Expand Up @@ -433,15 +434,15 @@ func UpdateSeriesVersions() error {
return nil
}

var updatedseriesVersions bool
var updatedSeriesVersions bool

func updateSeriesVersionsOnce() {
if !updatedseriesVersions {
if !updatedSeriesVersions {
if err := updateSeriesVersions(); err != nil {
logger.Warningf("failed to update distro info: %v", err)
}
updateVersionSeries()
updatedseriesVersions = true
updatedSeriesVersions = true
}
}

Expand Down

0 comments on commit f639f09

Please sign in to comment.