Skip to content

Commit

Permalink
add timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoPolo committed Oct 31, 2024
1 parent f9f39b7 commit 97051ab
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion p2p/transport/tcpreuse/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"net"
"sync"
"time"

logging "github.com/ipfs/go-log/v2"
"github.com/libp2p/go-libp2p/core/connmgr"
Expand All @@ -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.
Expand Down Expand Up @@ -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
}
}()
}
Expand Down

0 comments on commit 97051ab

Please sign in to comment.