Don't close connections twice after join completes #217
+2
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes a data race in the forwarder which can be hit by reading/writing data during a call to
(ngrok.Endpoint).CloseWithContext()and(ngrok.Agent).Disconnect().I've been unsuccessfully trying to get a small test to demonstrate it since I ran into it in a rather complex setup for an internal test. I'll see if I can get one working. However, my internal tests are now working perfectly fine with this fix and I'm no longer getting any races.
The underlying problem is that when a muxado stream is closed it does internal writes, but the
io.Copystill might be doing reads which races. This closes writes but waits for all reads to finish fromio.Copybefore entirely closing the connection. There was also some additionalClosecalls that are unnecessary sincejoincan handle them all.Investigated/written with the help of Amp, but it took a long time to get there lol.