Skip to content

Commit

Permalink
Fix node stop listening if too many open files and add retry count be…
Browse files Browse the repository at this point in the history
…fore panic

Signed-off-by: Yilun <[email protected]>
  • Loading branch information
yilunzhang committed Oct 5, 2018
1 parent 6bdbd31 commit fb8d74a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
11 changes: 10 additions & 1 deletion net/chord/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,18 +713,27 @@ func (t *TCPTransport) reapOnce() {

// Listens for inbound connections
func (t *TCPTransport) listen() {
errCount := 0
for {
conn, err := t.sock.AcceptTCP()
if err != nil {
if errCount < 10 {
errCount++
} else {
panic("Cannot accept new connections: " + err.Error())
}

if atomic.LoadInt32(&t.shutdown) == 0 {
log.Printf("[ERR] Error accepting TCP connection! %s\n", err)
time.Sleep(time.Millisecond * 300) // Add delay before try again sock Accept
time.Sleep(1 * time.Second)
continue
} else {
return
}
}

errCount = 0

// Setup the conn
t.setupConn(conn)

Expand Down
13 changes: 12 additions & 1 deletion net/node/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,23 @@ func (n *node) initConnection() {
return
}
}

errCount := 0
for {
conn, err := listener.Accept()
if err != nil {
if errCount < 10 {
errCount++
} else {
panic("Cannot accept new connections: " + err.Error())
}

log.Error("Error accepting ", err.Error())
return
time.Sleep(1 * time.Second)
continue
}

errCount = 0
log.Info("Remote node connect with ", conn.RemoteAddr(), conn.LocalAddr())

n.link.connCnt++
Expand Down

0 comments on commit fb8d74a

Please sign in to comment.