p2p: accept should not abort on first error

This commit is contained in:
tycho garen
2022-06-14 17:01:51 -04:00
parent 7971f4a2fc
commit a35a3a8f0b

View File

@@ -470,14 +470,17 @@ func (r *Router) dialSleep(ctx context.Context) {
func (r *Router) acceptPeers(ctx context.Context, transport Transport) {
for {
conn, err := transport.Accept(ctx)
switch err {
case nil:
case io.EOF:
r.logger.Debug("stopping accept routine", "transport", transport)
switch {
case errors.Is(err, context.Canceled), errors.Is(err, context.DeadlineExceeded):
r.logger.Debug("stopping accept routine", "transport", transport, "err", "context canceled")
return
default:
case errors.Is(err, io.EOF):
r.logger.Debug("stopping accept routine", "transport", transport, "err", "EOF")
return
case err != nil:
// in this case we got an error from the net.Listener.
r.logger.Error("failed to accept connection", "transport", transport, "err", err)
return
continue
}
incomingIP := conn.RemoteEndpoint().IP
@@ -489,7 +492,7 @@ func (r *Router) acceptPeers(ctx context.Context, transport Transport) {
"close_err", closeErr,
)
return
continue
}
// Spawn a goroutine for the handshake, to avoid head-of-line blocking.