natefinch / npipe

A Windows named pipe implementation written in pure Go.
MIT License
297 stars 73 forks source link

fix a race condition in PipeListener #21

Closed natefinch closed 8 years ago

natefinch commented 8 years ago

There was an obvious race between PipeListener's Accept and Close modifying l.closed, found with go test -race, and a less obvious race that if someone calls Close before we call connectnamedpipe, the connect would hang forever. Now we have a lock over the whole of Accept and Close (except while doing WaitSingleObject, which will corrently return an error when we Close), so Close can't screw up connect named pipe.

natefinch commented 8 years ago

Testing done: there was a test in juju (under worker/metrics/sender) that would occasionally hang (approx 1/10 times)... with this fix, no more hang in 300 trials.

(also go test -race used to find a race condition and now does not)