From bbedaf7173da0c27e11ecde710e5cb590cd8a1ab Mon Sep 17 00:00:00 2001 From: "yinxuran.lucky" Date: Tue, 24 Dec 2024 15:05:16 +0800 Subject: [PATCH] fix: call conn.release method in ext.ReleaseBodystream --- pkg/common/test/mock/network.go | 6 ++++-- pkg/protocol/http1/ext/stream.go | 14 +++++++++++++- pkg/protocol/http1/req/request_test.go | 1 + 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/pkg/common/test/mock/network.go b/pkg/common/test/mock/network.go index fe671ae56..5b67142d8 100644 --- a/pkg/common/test/mock/network.go +++ b/pkg/common/test/mock/network.go @@ -325,7 +325,8 @@ func (m *Conn) AddCloseCallback(callback netpoll.CloseCallback) error { } type StreamConn struct { - Data []byte + Data []byte + HasReleased bool } func NewStreamConn() *StreamConn { @@ -354,7 +355,8 @@ func (m *StreamConn) Skip(n int) error { } func (m *StreamConn) Release() error { - panic("implement me") + m.HasReleased = true + return nil } func (m *StreamConn) Len() int { diff --git a/pkg/protocol/http1/ext/stream.go b/pkg/protocol/http1/ext/stream.go index ae81b560e..51bb01d43 100644 --- a/pkg/protocol/http1/ext/stream.go +++ b/pkg/protocol/http1/ext/stream.go @@ -272,6 +272,11 @@ func (rs *bodyStream) skipRest() error { if err != nil { return err } + err = rs.reader.Release() + if err != nil { + return err + } + } } // max value of pSize is 8193, it's safe. @@ -300,7 +305,14 @@ func (rs *bodyStream) skipRest() error { if skip > needSkipLen { skip = needSkipLen } - rs.reader.Skip(skip) + err := rs.reader.Skip(skip) + if err != nil { + return err + } + err = rs.reader.Release() + if err != nil { + return err + } needSkipLen -= skip if needSkipLen == 0 { return nil diff --git a/pkg/protocol/http1/req/request_test.go b/pkg/protocol/http1/req/request_test.go index 0411187a5..e9451e776 100644 --- a/pkg/protocol/http1/req/request_test.go +++ b/pkg/protocol/http1/req/request_test.go @@ -1425,6 +1425,7 @@ func TestStreamNotEnoughData(t *testing.T) { err = ext.ReleaseBodyStream(req.BodyStream()) assert.Nil(t, err) assert.DeepEqual(t, 0, len(conn.Data)) + assert.DeepEqual(t, true, conn.HasReleased) } func TestRequestBodyStreamWithTrailer(t *testing.T) {