Commit d1f0342a authored by Matt Joiner's avatar Matt Joiner

Add SetLinger(0) in reuseDial

No longer implicitly provided by go-reuseport's Dialer as it was removed.
parent fed46568
......@@ -38,8 +38,9 @@ func reuseErrShouldRetry(err error) bool {
}
}
// Dials using reusport and then redials normally if that fails.
func reuseDial(ctx context.Context, laddr *net.TCPAddr, network, raddr string) (net.Conn, error) {
// 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) {
if laddr == nil {
return fallbackDialer.DialContext(ctx, network, raddr)
}
......@@ -48,8 +49,17 @@ func reuseDial(ctx context.Context, laddr *net.TCPAddr, network, raddr string) (
LocalAddr: laddr,
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 {
return con, nil
}
......
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