From 19e7961dd5b4bddd73ed7186d1544abdcf191ebe Mon Sep 17 00:00:00 2001 From: Kyle Xiao Date: Tue, 26 Nov 2024 18:21:34 +0800 Subject: [PATCH] fix(client): keep ref to resp to avoid conn closed --- client.go | 1 + conn.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/client.go b/client.go index c26ec71..b9f4564 100644 --- a/client.go +++ b/client.go @@ -86,5 +86,6 @@ func (p *ClientUpgrader) UpgradeResponse(req *protocol.Request, resp *protocol.R conn.newCompressionWriter = compressNoContextTakeover conn.newDecompressionReader = decompressNoContextTakeover } + conn.resp = resp return conn, nil } diff --git a/conn.go b/conn.go index 2eb8874..3805bd0 100644 --- a/conn.go +++ b/conn.go @@ -282,6 +282,10 @@ type Conn struct { readDecompress bool // whether last read frame had RSV1 set newDecompressionReader func(io.Reader) io.ReadCloser + + // keep reference to the resp to make sure the underyling conn will not be closed. + // see: https://github.com/cloudwego/hertz/pull/1214 for the details. + resp interface{} // *protocol.Response } func newConn(conn net.Conn, isServer bool, readBufferSize, writeBufferSize int, writeBufferPool BufferPool, br *bufio.Reader, writeBuf []byte) *Conn {