Skip to content
This repository was archived by the owner on Mar 11, 2020. It is now read-only.

Commit 4be445c

Browse files
committed
retry listen
Devices that are still in the ipv6 duplicated address detection will fail to bind so retry every 100ms for upto 3s. Signed-off-by: Tom Grennan <[email protected]>
1 parent d92dd30 commit 4be445c

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

server.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package redis
77
import (
88
"bufio"
99
"fmt"
10+
"time"
1011
// "io"
1112
// "io/ioutil"
1213
"net"
@@ -36,14 +37,22 @@ func (srv *Server) listen() error {
3637
addr = ":6389"
3738
}
3839
}
39-
l, e := net.Listen(srv.Proto, addr)
40-
if e != nil {
41-
return e
40+
for i := 0; ; i++ {
41+
l, e := net.Listen(srv.Proto, addr)
42+
if e == nil {
43+
srv.listener = l
44+
break
45+
} else if i < 30 {
46+
// retry for devices that are still in ipv6
47+
// duplicate address detection
48+
time.Sleep(100 * time.Millisecond)
49+
} else {
50+
return e
51+
}
4252
}
43-
srv.listener = l
4453

4554
// if port was 0 and proto is tcp, the listener would use a random port
46-
srv.Addr = l.Addr().String()
55+
srv.Addr = srv.listener.Addr().String()
4756
return nil
4857
}
4958

0 commit comments

Comments
 (0)