From 1a1327b6e8e3edbd652ba59f8e9e6fe56557bc17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Tue, 16 Jul 2024 23:14:15 +0900 Subject: [PATCH] fix(tcp): early quit of recv --- gold/p2p/tcp/tcp.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/gold/p2p/tcp/tcp.go b/gold/p2p/tcp/tcp.go index c9cae00..372df95 100644 --- a/gold/p2p/tcp/tcp.go +++ b/gold/p2p/tcp/tcp.go @@ -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 { @@ -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{}{} }) @@ -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() }