From 4f149c214c250929944203a8acd9cac798f4534d Mon Sep 17 00:00:00 2001 From: Irine Sistiana <49315432+IrineSistiana@users.noreply.github.com> Date: Wed, 1 Nov 2023 15:13:20 +0800 Subject: [PATCH] transport: fixed Test_ReuseConnTransport may fail --- pkg/upstream/transport/reuse.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/upstream/transport/reuse.go b/pkg/upstream/transport/reuse.go index 89a69d686..0cf35fd76 100644 --- a/pkg/upstream/transport/reuse.go +++ b/pkg/upstream/transport/reuse.go @@ -267,16 +267,17 @@ func (c *reusableConn) readLoop() { return } + // This connection is idled again. + c.c.SetReadDeadline(time.Now().Add(c.t.idleTimeout)) + // Note: calling setIdle before sending resp back to make sure this connection is idle + // before Exchange call returning. Otherwise, Test_ReuseConnTransport may fail. + c.t.setIdle(c) + select { case respChan <- resp: default: panic("bug: respChan has buffer, we shouldn't reach here") } - - // this connection is idled again - c.c.SetReadDeadline(time.Now().Add(c.t.idleTimeout)) - c.t.setIdle(c) - } }