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

pkg/pwalk: fix data race with err #109

Merged
merged 1 commit into from
Jul 1, 2020

Conversation

kolyshkin
Copy link
Collaborator

@kolyshkin kolyshkin commented Jul 1, 2020

Fixes: #108

Go race detector found a race in the code wrt err read/write:

cd pkg/pwalk && go test -run Many -race .
RUN TestWalkManyErrors

WARNING: DATA RACE
Read at 0x00c0000a0510 by goroutine 7:
github.com/opencontainers/selinux/pkg/pwalk.WalkN()
/home/kir/go/src/github.com/opencontainers/selinux/pkg/pwalk/pwalk.go:91 +0x1f8
github.com/opencontainers/selinux/pkg/pwalk.Walk()
/home/kir/go/src/github.com/opencontainers/selinux/pkg/pwalk/pwalk.go:35 +0x321
...
Previous write at 0x00c0000a0510 by goroutine 8:
github.com/opencontainers/selinux/pkg/pwalk.WalkN.func1()
/home/kir/go/src/github.com/opencontainers/selinux/pkg/pwalk/pwalk.go:53 +0xa6
...

Indeed, we wait for all runner goroutines but do not wait for the
filetree reading goroutine (the one that calls filepath.Walk).

One way to fix it would be to not assign value to global variable err in
the filetree reading goroutine, but do that in a runner. Unfortunately,
that way we might mix up and not return the first error.

Fix by using waitgroup for the reading goroutine as well. Slightly
more complex than not assiging err in there, but guarantee we'll
return the first error.

Go race detector found a race in the code wrt err read/write:

> $ cd pkg/pwalk && go test -run Many -race .
> === RUN   TestWalkManyErrors
> ==================
> WARNING: DATA RACE
> Read at 0x00c0000a0510 by goroutine 7:
>   github.com/opencontainers/selinux/pkg/pwalk.WalkN()
>       /home/kir/go/src/github.com/opencontainers/selinux/pkg/pwalk/pwalk.go:91 +0x1f8
>   github.com/opencontainers/selinux/pkg/pwalk.Walk()
>       /home/kir/go/src/github.com/opencontainers/selinux/pkg/pwalk/pwalk.go:35 +0x321
> ...
> Previous write at 0x00c0000a0510 by goroutine 8:
>   github.com/opencontainers/selinux/pkg/pwalk.WalkN.func1()
>       /home/kir/go/src/github.com/opencontainers/selinux/pkg/pwalk/pwalk.go:53 +0xa6

Indeed, we wait for all runner goroutines but do not wait for the
filetree reading goroutine (the one that calls filepath.Walk).

One way to fix it would be to not assign value to global variable err in
the filetree reading goroutine, but do that in a runner. Unfortunately,
that way we might mix up and not return the first error.

Fix by using waitgroup for the reading goroutine as well.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@rhatdan
Copy link
Collaborator

rhatdan commented Jul 1, 2020

LGTM
@yulicrunchy PTAL

Approved with PullApprove

@gitstashpop
Copy link
Contributor

lgtm and verified locally

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kolyshkin
Copy link
Collaborator Author

@thaJeztah you have to add the LGTM comment as well since this repo is using pullapprove*

*which maybe we should ditch as we did in runc, opencontainers/runc#2388

@thaJeztah
Copy link
Member

ooooh, so it doesn't look at "reviews", only "comments"?

@thaJeztah
Copy link
Member

thaJeztah commented Jul 1, 2020

LGTM

Approved with PullApprove

@thaJeztah
Copy link
Member

oh, wow, that's "silly"

@thaJeztah thaJeztah merged commit dad7ff9 into opencontainers:master Jul 1, 2020
@thaJeztah
Copy link
Member

Looks like there's support for github reviews in the v2 syntax that we're using (https://v2-docs.pullapprove.com/groups/github_reviews/), but v3 is the current version of the config format (not sure if that allows approval through comments), but yes, I think GitHub's native reviews should work fine for this

@kolyshkin
Copy link
Collaborator Author

GitHub's native reviews should work fine for this

except for people who use email to LGTM (I'm not sure we have anyone doing that in here)

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.

data race exists in pwalk
4 participants