Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

blob/s3blob: fix data race#3480

Merged
vangent merged 1 commit intogoogle:masterfrom
arjunnair1997:arjun/fix_data_race
Aug 29, 2024
Merged

blob/s3blob: fix data race#3480
vangent merged 1 commit intogoogle:masterfrom
arjunnair1997:arjun/fix_data_race

Conversation

Copy link
Contributor

arjunnair1997 commented Aug 29, 2024

w.pr cannot be used to indicate that the pipe has been closed. Instead, we use an atomic.Bool. The problem with using w.pr is that a write to it in the goroutine launched by writer.open can race with a read on w.pr in Close.

Note that it's still possible that w.pr.CloseWithError runs concurrently with w.pr.Close. But this is fine.

Copy link

google-cla bot commented Aug 29, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

richardartoul approved these changes Aug 29, 2024
Copy link
Contributor

richardartoul left a comment

Choose a reason for hiding this comment

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

LGTM, although wondering if we could just allow w.pr to be closed twice because it looks like thats concurrency safe:

func (p *pipe) closeRead(err error) error {
if err == nil {
err = ErrClosedPipe
}
p.rerr.Store(err)
p.once.Do(func() { close(p.done) })
return nil
}

vangent requested changes Aug 29, 2024
Copy link
Contributor

vangent left a comment

Choose a reason for hiding this comment

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

I see the race you are describing, but I don't think this PR completely fixes it. I think it changes the race from "might result in a nil access" to "might result in a double-Close".

It looks like double-Close is actually fine though (https://play.golang.com/p/WvceCRttXVU).

So I think it should be sufficient to drop the "prClosed" entirely, and just remove the "w.pr = nil" line (line 383). WDYT?

Copy link
Contributor

vangent commented Aug 29, 2024

Ha, my review raced with @richardartoul :-). Glad we came to the same conclusion though.

Copy link

codecov bot commented Aug 29, 2024 *
edited
Loading

Codecov Report

All modified and coverable lines are covered by tests

Project coverage is 73.14%. Comparing base (bb796f8) to head (08ff5df).
Report is 1 commits behind head on master.

Additional details and impacted files
@@ Coverage Diff @@
## master #3480 +/- ##
==========================================
- Coverage 73.15% 73.14% -0.01%
==========================================
Files 113 113
Lines 14984 14983 -1
==========================================
- Hits 10961 10960 -1
Misses 3260 3260
Partials 763 763

View full report in Codecov by Sentry.
Have feedback on the report? Share it here.

w.pr cannot be used to indicate that the pipe has been closed. The problem with
using w.pr is that a write to it in the goroutine launched by writer.open can
race with a read on w.pr in Close.

We just don't write to w.pr in writer.open. The read end of the pipe can still be
closed twice, but that's fine.
arjunnair1997 force-pushed the arjun/fix_data_race branch from cbf04e9 to 08ff5df Compare August 29, 2024 21:48
Copy link
Contributor Author

arjunnair1997 commented Aug 29, 2024 *
edited
Loading

Yea, I think it could double close the read end of the pipe before my change too, but it's just simpler to not use an atomic.Bool. Updated the pr, please take a look.

arjunnair1997 requested a review from vangent August 29, 2024 21:49
vangent approved these changes Aug 29, 2024
vangent merged commit 2d0cce5 into google:master Aug 29, 2024
Copy link
Contributor

vangent commented Aug 29, 2024

Thanks!

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

Reviewers

vangent vangent approved these changes

+1 more reviewer

richardartoul richardartoul approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants