fix: don't close tuic when read timeout

This commit is contained in:
wwqgtxx 2022-11-25 11:04:28 +08:00
parent 30ca59dab7
commit 142d17ebad

View file

@ -214,22 +214,26 @@ func (t *Client) DialContext(ctx context.Context, metadata *C.Metadata, dialFn f
if err != nil {
return nil, err
}
defer func() {
t.deferQuicConn(quicConn, err)
stream, err := func() (quic.Stream, error) {
defer func() {
t.deferQuicConn(quicConn, err)
}()
buf := &bytes.Buffer{}
err = NewConnect(NewAddress(metadata)).WriteTo(buf)
if err != nil {
return nil, err
}
stream, err := quicConn.OpenStream()
if err != nil {
return nil, err
}
_, err = buf.WriteTo(stream)
if err != nil {
return nil, err
}
return stream, err
}()
buf := &bytes.Buffer{}
err = NewConnect(NewAddress(metadata)).WriteTo(buf)
if err != nil {
return nil, err
}
stream, err := quicConn.OpenStream()
if err != nil {
return nil, err
}
_, err = buf.WriteTo(stream)
if err != nil {
return nil, err
}
if t.RequestTimeout > 0 {
_ = stream.SetReadDeadline(time.Now().Add(time.Duration(t.RequestTimeout) * time.Millisecond))
}