Skip to content

Commit

Permalink
fix(tcp): early quit of recv
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Jul 16, 2024
1 parent 9a63b3c commit 1a1327b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions gold/p2p/tcp/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,11 @@ func (conn *Conn) accept() {
}

func (conn *Conn) receive(ep *EndPoint) {
dialtimeout := conn.addr.dialtimeout
if dialtimeout < time.Second {
dialtimeout = time.Second
peerstimeout := ep.peerstimeout
if peerstimeout < time.Second {
peerstimeout = time.Second * 5
}
peerstimeout *= 2
for {
r := &connrecv{addr: ep}
if conn.addr == nil || conn.lstn == nil || conn.peers == nil || conn.recv == nil {
Expand All @@ -132,7 +133,7 @@ func (conn *Conn) receive(ep *EndPoint) {
r.conn = tcpconn

stopch := make(chan struct{})
t := time.AfterFunc(dialtimeout, func() {
t := time.AfterFunc(peerstimeout, func() {
stopch <- struct{}{}
})

Expand All @@ -146,7 +147,7 @@ func (conn *Conn) receive(ep *EndPoint) {
select {
case <-stopch:
logrus.Debugln("[tcp] recv from", ep, "timeout")
return
continue
case <-copych:
t.Stop()
}
Expand Down

0 comments on commit 1a1327b

Please sign in to comment.