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

Commit

Permalink
retry listen
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
tgrennan committed Jun 7, 2016
1 parent d92dd30 commit 4be445c
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package redis
import (
"bufio"
"fmt"
"time"
// "io"
// "io/ioutil"
"net"
Expand Down Expand Up @@ -36,14 +37,22 @@ func (srv *Server) listen() error {
addr = ":6389"
}
}
l, e := net.Listen(srv.Proto, addr)
if e != nil {
return e
for i := 0; ; i++ {
l, e := net.Listen(srv.Proto, addr)
if e == nil {
srv.listener = l
break
} else if i < 30 {
// retry for devices that are still in ipv6
// duplicate address detection
time.Sleep(100 * time.Millisecond)
} else {
return e
}
}
srv.listener = l

// if port was 0 and proto is tcp, the listener would use a random port
srv.Addr = l.Addr().String()
srv.Addr = srv.listener.Addr().String()
return nil
}

Expand Down

0 comments on commit 4be445c

Please sign in to comment.