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

command/expand: fix data race for concurrent writes #330

Merged
merged 3 commits into from
Aug 2, 2021
Merged

Conversation

sonmezonur
Copy link
Member

  • Concurrent write to objFound bool is not thread-safe. Use atomic boolean to avoid data race.

When I run TestExpandSources with the race detector, it shows data race warnings.

go test -race -mod=vendor -count=1 -run="TestExpandSources" ./...

WARNING: DATA RACE
Write at 0x00c0000b673c by goroutine 30:
  github.com/peak/s5cmd/command.expandSources.func1.1()
      .../go/src/github.com/peak/s5cmd/command/expand.go:79 +0x1d5

Previous write at 0x00c0000b673c by goroutine 29:
  github.com/peak/s5cmd/command.expandSources.func1.1()
      .../go/src/github.com/peak/s5cmd/command/expand.go:79 +0x1d5

Goroutine 30 (running) created at:
  github.com/peak/s5cmd/command.expandSources.func1()
      .../go/src/github.com/peak/s5cmd/command/expand.go:65 +0x1e5

Goroutine 29 (finished) created at:
  github.com/peak/s5cmd/command.expandSources.func1()
      .../go/src/github.com/peak/s5cmd/command/expand.go:65 +0x1e5

* Concurrent write to objFound bool is not thread-safe. Use atomic boolean
  to avoid data race.
@sonmezonur sonmezonur requested a review from a team as a code owner July 29, 2021 10:15
@sonmezonur sonmezonur requested review from igungor and aykutfarsak and removed request for a team July 29, 2021 10:15
@sonmezonur sonmezonur merged commit d80fc02 into master Aug 2, 2021
@sonmezonur sonmezonur deleted the atomic_bool branch August 2, 2021 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants