From 9b1fe9f46609e46cec03b05a5c262045975008c7 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Fri, 25 Nov 2022 16:06:56 +0800 Subject: [PATCH] fix: tuic stream close --- transport/tuic/client.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/transport/tuic/client.go b/transport/tuic/client.go index 88f385a1..18e623ab 100644 --- a/transport/tuic/client.go +++ b/transport/tuic/client.go @@ -209,7 +209,7 @@ func (t *Client) deferQuicConn(quicConn quic.Connection, err error) { func (t *Client) Close(err error) { quicConn := t.quicConn if quicConn != nil { - _ = t.quicConn.CloseWithError(ProtocolError, err.Error()) + _ = quicConn.CloseWithError(ProtocolError, err.Error()) t.udpInputMap.Range(func(key, value any) bool { if conn, ok := value.(net.Conn); ok { _ = conn.Close() @@ -256,14 +256,15 @@ func (t *Client) DialContext(ctx context.Context, metadata *C.Metadata, dialFn f conn := N.NewBufferedConn(&quicStreamConn{stream, quicConn.LocalAddr(), quicConn.RemoteAddr(), t}) response, err := ReadResponse(conn) if err != nil { + _ = conn.Close() return nil, err } if response.IsFailed() { - _ = stream.Close() + _ = conn.Close() return nil, errors.New("connect failed") } _ = stream.SetReadDeadline(time.Time{}) - return conn, err + return conn, nil } type quicStreamConn struct { @@ -273,6 +274,11 @@ type quicStreamConn struct { client *Client } +func (q *quicStreamConn) Close() error { + q.Stream.CancelRead(0) + return q.Stream.Close() +} + func (q *quicStreamConn) LocalAddr() net.Addr { return q.lAddr }