Fix payload not return to pool

This commit is contained in:
世界 2023-09-24 14:39:56 +08:00
parent 5a1ddea100
commit 4fb227ed86
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -178,6 +178,7 @@ func CopyEarlyConn(ctx context.Context, conn net.Conn, serverConn net.Conn) erro
payload := cachedReader.ReadCached() payload := cachedReader.ReadCached()
if payload != nil && !payload.IsEmpty() { if payload != nil && !payload.IsEmpty() {
_, err := serverConn.Write(payload.Bytes()) _, err := serverConn.Write(payload.Bytes())
payload.Release()
if err != nil { if err != nil {
return err return err
} }
@ -189,10 +190,12 @@ func CopyEarlyConn(ctx context.Context, conn net.Conn, serverConn net.Conn) erro
err := conn.SetReadDeadline(time.Now().Add(C.ReadPayloadTimeout)) err := conn.SetReadDeadline(time.Now().Add(C.ReadPayloadTimeout))
if err != os.ErrInvalid { if err != os.ErrInvalid {
if err != nil { if err != nil {
payload.Release()
return err return err
} }
_, err = payload.ReadOnceFrom(conn) _, err = payload.ReadOnceFrom(conn)
if err != nil && !E.IsTimeout(err) { if err != nil && !E.IsTimeout(err) {
payload.Release()
return E.Cause(err, "read payload") return E.Cause(err, "read payload")
} }
err = conn.SetReadDeadline(time.Time{}) err = conn.SetReadDeadline(time.Time{})
@ -202,10 +205,10 @@ func CopyEarlyConn(ctx context.Context, conn net.Conn, serverConn net.Conn) erro
} }
} }
_, err = serverConn.Write(payload.Bytes()) _, err = serverConn.Write(payload.Bytes())
payload.Release()
if err != nil { if err != nil {
return N.ReportHandshakeFailure(conn, err) return N.ReportHandshakeFailure(conn, err)
} }
payload.Release()
} }
return bufio.CopyConn(ctx, conn, serverConn) return bufio.CopyConn(ctx, conn, serverConn)
} }