Skip to content
This repository has been archived by the owner on Mar 11, 2020. It is now read-only.

Fix race-y channel close/error assignment #21

Merged
merged 1 commit into from
Aug 12, 2016

Conversation

nilium
Copy link
Contributor

@nilium nilium commented Jul 24, 2016

Data race occurred when assigning to err and then subsequently reading
it from anywhere else. Moving the channel close down could potentially
help, but far easier to just gate both with a sync.Once since this
isn't a code path that seems like it needs to be super-performant.

Changes cause CloseWithError to be call-able once, ensuring that
there's no case where err is written to while being read (as would
happen when closing and reading c.err from another goroutine the moment
c.closed is closed).

Signed-off-by: Noel Cower ncower@gmail.com

Data race occurred when assigning to err and then subsequently reading
it from anywhere else. Moving the channel close down could potentially
help, but far easier to just gate both with a sync.Once since this
isn't a code path that seems like it needs to be super-performant.

Changes cause CloseWithError to be call-able once, ensuring that
there's no case where err is written to while being read (as would
happen when closing and reading c.err from another goroutine the moment
c.closed is closed).

Signed-off-by: Noel Cower <ncower@gmail.com>
@codecov-io
Copy link

codecov-io commented Jul 24, 2016

Current coverage is 15.97% (diff: 0.00%)

Merging #21 into master will increase coverage by 0.05%

@@             master        #21   diff @@
==========================================
  Files            13         13          
  Lines          1131       1127     -4   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
  Hits            180        180          
+ Misses          903        899     -4   
  Partials         48         48          

Powered by Codecov. Last update 87c6cf4...2248b90

@nilium
Copy link
Contributor Author

nilium commented Jul 24, 2016

Working on throwing together a small-ish example to reproduce this without dumping all my code somewhere. However, it should hopefully be visible with -race enabled (and using p9p.Dispatch to handle sessions, in my case). If you mount and then unmount a remote (the program using go-p9p), the runtime should detect a data race around c.err read/assign statements. Not sure if this is only visible when using mac9p or if it would also apply when using v9fs.

@stevvooe
Copy link
Contributor

LGTM

@stevvooe stevvooe merged commit 4f41ff6 into docker-archive:master Aug 12, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants