aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-08-19 20:35:01 +0800
committerFelix Lange <fjl@twurst.com>2015-08-19 20:39:04 +0800
commitedccc7ae3430836141b803c252f26bf1ef98d185 (patch)
treef07d3d4adfc73a88a9bedf5f4529c1eab07b702c
parent7d5ff770e22a3791c0f9c2794a19f59ca2756b33 (diff)
downloadgo-tangerine-edccc7ae3430836141b803c252f26bf1ef98d185.tar.gz
go-tangerine-edccc7ae3430836141b803c252f26bf1ef98d185.tar.zst
go-tangerine-edccc7ae3430836141b803c252f26bf1ef98d185.zip
p2p: continue listening after temporary errors
-rw-r--r--p2p/server.go31
1 files changed, 25 insertions, 6 deletions
diff --git a/p2p/server.go b/p2p/server.go
index 7351a2654..d8be85323 100644
--- a/p2p/server.go
+++ b/p2p/server.go
@@ -542,6 +542,10 @@ func (srv *Server) encHandshakeChecks(peers map[discover.NodeID]*Peer, c *conn)
}
}
+type tempError interface {
+ Temporary() bool
+}
+
// listenLoop runs in its own goroutine and accepts
// inbound connections.
func (srv *Server) listenLoop() {
@@ -561,16 +565,31 @@ func (srv *Server) listenLoop() {
}
for {
+ // Wait for a handshake slot before accepting.
<-slots
- fd, err := srv.listener.Accept()
- if err != nil {
- return
+
+ var (
+ fd net.Conn
+ err error
+ )
+ for {
+ fd, err = srv.listener.Accept()
+ if tempErr, ok := err.(tempError); ok && tempErr.Temporary() {
+ glog.V(logger.Debug).Infof("Temporary read error: %v", err)
+ continue
+ } else if err != nil {
+ glog.V(logger.Debug).Infof("Read error: %v", err)
+ return
+ }
+ break
}
- mfd := newMeteredConn(fd, true)
+ fd = newMeteredConn(fd, true)
+ glog.V(logger.Debug).Infof("Accepted conn %v\n", fd.RemoteAddr())
- glog.V(logger.Debug).Infof("Accepted conn %v\n", mfd.RemoteAddr())
+ // Spawn the handler. It will give the slot back when the connection
+ // has been established.
go func() {
- srv.setupConn(mfd, inboundConn, nil)
+ srv.setupConn(fd, inboundConn, nil)
slots <- struct{}{}
}()
}