This repository has been archived by the owner on May 26, 2022. It is now read-only.
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.
Fixes #33. Fixes #40.
This PR fixes the tests on OSX. The problem we were running into is that when trying to reuse an existing port in
go-reuseport-transport/reuseport.go
Lines 23 to 28 in fe436d7
we'd get an error "connect: address already in use".
This was very surprising to me at first, after all SO_REUSEPORT should allow us to reuse ports. It's explained in this document:
What's happening is that we're connection
A <-> B
first, then close that connection, and later try to connectA <-> B
first. If the FIN is not properly acknowledged, the connection is still in the TIME_WAIT state, and we cannot reuse the port as described in the quote above.The question is why this only happens on OSX, and here's where I can't really find out. My best guess is differences in Linux's and Mac's TCP stack. Using Wireshark, I could however confirm that this is what's actually going on.
Here's the trace recorded on OSX (trace_osx.pcapng.zip):
And here on Ubuntu (trace_ubuntu.pcapng.zip):
Note the ACK for the FIN, that's missing on OSX.
For libp2p, this is not a problem, as we always set linger to 0 in https://github.com/libp2p/go-libp2p/blob/39fd9a03b0946f475881ae07038014135e3021f1/p2p/transport/tcp/tcp.go#L188-L191.