Commit 49f05fae authored by Steven Allen's avatar Steven Allen

don't set linger to 0

We should do this from
go-tcp-transport (https://github.com/libp2p/go-tcp-transport/pull/36), not here,
as setting linger to 0 will cause us to send RST packets instead of nicely
closing connections.

Also, document why we need the fallback dialer.
parent 501048f8
...@@ -39,7 +39,6 @@ func reuseErrShouldRetry(err error) bool { ...@@ -39,7 +39,6 @@ func reuseErrShouldRetry(err error) bool {
} }
// Dials using reuseport and then redials normally if that fails. // Dials using reuseport and then redials normally if that fails.
// TODO(anacrolix): This shouldn't fail anymore: Remove fallback.
func reuseDial(ctx context.Context, laddr *net.TCPAddr, network, raddr string) (con net.Conn, err error) { func reuseDial(ctx context.Context, laddr *net.TCPAddr, network, raddr string) (con net.Conn, err error) {
if laddr == nil { if laddr == nil {
return fallbackDialer.DialContext(ctx, network, raddr) return fallbackDialer.DialContext(ctx, network, raddr)
...@@ -49,15 +48,6 @@ func reuseDial(ctx context.Context, laddr *net.TCPAddr, network, raddr string) ( ...@@ -49,15 +48,6 @@ func reuseDial(ctx context.Context, laddr *net.TCPAddr, network, raddr string) (
LocalAddr: laddr, LocalAddr: laddr,
Control: reuseport.Control, Control: reuseport.Control,
} }
defer func() {
if err != nil {
return
}
// This is transplanted from go-reuseport, which once set no linger on
// dialing and may be a requirement for desired behaviour in this
// package.
con.(*net.TCPConn).SetLinger(0)
}()
con, err = d.DialContext(ctx, network, raddr) con, err = d.DialContext(ctx, network, raddr)
if err == nil { if err == nil {
...@@ -65,6 +55,8 @@ func reuseDial(ctx context.Context, laddr *net.TCPAddr, network, raddr string) ( ...@@ -65,6 +55,8 @@ func reuseDial(ctx context.Context, laddr *net.TCPAddr, network, raddr string) (
} }
if reuseErrShouldRetry(err) && ctx.Err() == nil { if reuseErrShouldRetry(err) && ctx.Err() == nil {
// We could have an existing socket open or we could have one
// stuck in TIME-WAIT.
log.Debugf("failed to reuse port, dialing with a random port: %s", err) log.Debugf("failed to reuse port, dialing with a random port: %s", err)
con, err = fallbackDialer.DialContext(ctx, network, raddr) con, err = fallbackDialer.DialContext(ctx, network, raddr)
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment