Unverified Commit c7583c88 authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #14 from libp2p/fix/linger

don't set linger to 0
parents 501048f8 49f05fae
...@@ -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