mirror of
https://github.com/libp2p/go-reuseport.git
synced 2025-11-03 10:01:04 +08:00
disregard eaddrinuse
This commit is contained in:
17
impl_unix.go
17
impl_unix.go
@@ -108,10 +108,6 @@ func dial(dialer net.Dialer, netw, addr string) (c net.Conn, err error) {
|
||||
}
|
||||
}
|
||||
|
||||
// try to connect in a loop for EADDRINUSE errors.
|
||||
start := time.Now()
|
||||
for {
|
||||
|
||||
if fd, err = socket(rfamily, socktype, rprotocol); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -123,23 +119,10 @@ func dial(dialer net.Dialer, netw, addr string) (c net.Conn, err error) {
|
||||
}
|
||||
if err = connect(fd, remoteSockaddr); err != nil {
|
||||
syscall.Close(fd)
|
||||
if err == syscall.EADDRINUSE {
|
||||
// if we've waited longer than 2 seconds bail.
|
||||
if time.Now().Sub(start) > 2*time.Second {
|
||||
return nil, err
|
||||
}
|
||||
// otherwise, wait a bit and try again
|
||||
<-time.After(20 * time.Microsecond)
|
||||
continue
|
||||
}
|
||||
|
||||
// fmt.Println("connect failed", localSockaddr, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
if rprotocol == syscall.IPPROTO_TCP {
|
||||
// by default golang/net sets TCP no delay to true.
|
||||
if err = setNoDelay(fd, true); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user