Skip to content

Commit

Permalink
Merge pull request #38 from reef-pi/fix_race_condition
Browse files Browse the repository at this point in the history
(bug)take lock before reading map value in noop pwm driver
  • Loading branch information
ranjib authored Jan 16, 2022
2 parents 95fff2a + 03ca8c9 commit 9ab406e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ jobs:
with:
go-version: '^1.16.1'
- uses: codecov/codecov-action@v1
- run: go test ./...
- run: go test -cover -race ./...
- run: go build ./...
5 changes: 4 additions & 1 deletion pwm/noop_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ func Noop() (Driver, *recorder) {
return nil
},
readFile: func(f string) ([]byte, error) {
if _, ok := rec.values[f]; !ok {
rec.mu.Lock()
_, ok := rec.values[f]
rec.mu.Unlock()
if !ok {
return []byte{}, nil
}
return rec.values[f], nil
Expand Down

0 comments on commit 9ab406e

Please sign in to comment.