From ac322679e04cc9cf927430f9c1cd097907ee2b8c Mon Sep 17 00:00:00 2001 From: talrasha007 Date: Sat, 1 Mar 2025 18:29:18 +0800 Subject: [PATCH] Fix grpclite memory leak issue, close reader's underlying io.Reader. --- transport/v2raygrpclite/conn.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/transport/v2raygrpclite/conn.go b/transport/v2raygrpclite/conn.go index 5ab02569..7e5733c8 100644 --- a/transport/v2raygrpclite/conn.go +++ b/transport/v2raygrpclite/conn.go @@ -21,6 +21,7 @@ import ( var _ net.Conn = (*GunConn)(nil) type GunConn struct { + rd io.Reader reader *std_bufio.Reader writer io.Writer flusher http.Flusher @@ -31,6 +32,7 @@ type GunConn struct { func newGunConn(reader io.Reader, writer io.Writer, flusher http.Flusher) *GunConn { return &GunConn{ + rd: reader, reader: std_bufio.NewReader(reader), writer: writer, flusher: flusher, @@ -46,6 +48,7 @@ func newLateGunConn(writer io.Writer) *GunConn { func (c *GunConn) setup(reader io.Reader, err error) { if reader != nil { + c.rd = reader c.reader = std_bufio.NewReader(reader) } c.err = err @@ -138,7 +141,7 @@ func (c *GunConn) FrontHeadroom() int { } func (c *GunConn) Close() error { - return common.Close(c.reader, c.writer) + return common.Close(c.rd, c.writer) } func (c *GunConn) LocalAddr() net.Addr {