Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scd4x: data race in its unit test #84

Closed
maruel opened this issue Dec 7, 2024 · 0 comments
Closed

scd4x: data race in its unit test #84

maruel opened this issue Dec 7, 2024 · 0 comments

Comments

@maruel
Copy link
Member

maruel commented Dec 7, 2024

Describe the bug
A race condition in the scd4x driver.

To Reproduce

go test -race, e.g. Example: https://github.com/periph/devices/actions/runs/12216048416/job/34078745883?pr=8

==================
WARNING: DATA RACE
Read at 0x00c000218078 by goroutine 18:
  periph.io/x/devices/v3/scd4x.(*Dev).Sense()
      D:/a/devices/devices/scd4x/scd4x.go:533 +0xd9
  periph.io/x/devices/v3/scd4x.(*Dev).SenseContinuous.func1()
      D:/a/devices/devices/scd4x/scd4x.go:600 +0x351

Previous write at 0x00c000218078 by goroutine 19:
  periph.io/x/devices/v3/scd4x.(*Dev).Halt()
      D:/a/devices/devices/scd4x/scd4x.go:373 +0x[133](https://github.com/periph/devices/actions/runs/12216048416/job/34078745883?pr=83#step:9:134)
  periph.io/x/devices/v3/scd4x.TestSenseContinuous.func2()
      D:/a/devices/devices/scd4x/scd4x_test.go:257 +0x4f

Goroutine 18 (running) created at:
  periph.io/x/devices/v3/scd4x.(*Dev).SenseContinuous()
      D:/a/devices/devices/scd4x/scd4x.go:583 +0x1bb
  periph.io/x/devices/v3/scd4x.TestSenseContinuous()
      D:/a/devices/devices/scd4x/scd4x_test.go:250 +0x33c
  testing.tRunner()
      C:/hostedtoolcache/windows/go/1.22.6/x64/src/testing/testing.go:1689 +0x21e
  testing.(*T).Run.gowrap1()
      C:/hostedtoolcache/windows/go/1.22.6/x64/src/testing/testing.go:1742 +0x44

Goroutine 19 (running) created at:
  periph.io/x/devices/v3/scd4x.TestSenseContinuous()
      D:/a/devices/devices/scd4x/scd4x_test.go:255 +0x479
  testing.tRunner()
      C:/hostedtoolcache/windows/go/1.22.6/x64/src/testing/testing.go:1689 +0x21e
  testing.(*T).Run.gowrap1()
      C:/hostedtoolcache/windows/go/1.22.6/x64/src/testing/testing.go:1742 +0x44
==================

https://github.com/periph/devices/blob/main/scd4x/scd4x.go#L533
https://github.com/periph/devices/blob/main/scd4x/scd4x.go#L373

Fix

Add a d.mu.Lock() + Unlock around line 533 when reading d.sensing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant