diff --git a/p2p/transport/tcpreuse/listener.go b/p2p/transport/tcpreuse/listener.go index 0cbfd0738c..d5f2e12715 100644 --- a/p2p/transport/tcpreuse/listener.go +++ b/p2p/transport/tcpreuse/listener.go @@ -6,6 +6,7 @@ import ( "fmt" "net" "sync" + "time" logging "github.com/ipfs/go-log/v2" "github.com/libp2p/go-libp2p/core/connmgr" @@ -18,6 +19,9 @@ import ( const acceptQueueSize = 64 // It is fine to read 3 bytes from 64 connections in parallel. +// How long we wait for a connection to be accepted before dropping it. +const acceptTimeout = 30 * time.Second + var log = logging.Logger("tcp-demultiplex") // ConnMgr enables you to share the same listen address between TCP and WebSocket transports. @@ -254,9 +258,10 @@ func (m *multiplexedListener) run() error { select { case demux.buffer <- connWithScope: + case <-time.After(acceptTimeout): + connWithScope.Close() case <-m.ctx.Done(): connWithScope.Close() - return } }() }