mirror of
https://github.com/cmz0228/hysteria-dev.git
synced 2025-06-09 13:59:54 +00:00
fix: broken reconnect logic introduced in c62dc51
This commit is contained in:
parent
3a77d4756e
commit
4cf253efec
@ -172,13 +172,13 @@ func (c *clientImpl) openStream() (quic.Stream, error) {
|
|||||||
func (c *clientImpl) TCP(addr string) (net.Conn, error) {
|
func (c *clientImpl) TCP(addr string) (net.Conn, error) {
|
||||||
stream, err := c.openStream()
|
stream, err := c.openStream()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, maybeWrapQUICClosedError(err)
|
return nil, wrapIfConnectionClosed(err)
|
||||||
}
|
}
|
||||||
// Send request
|
// Send request
|
||||||
err = protocol.WriteTCPRequest(stream, addr)
|
err = protocol.WriteTCPRequest(stream, addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = stream.Close()
|
_ = stream.Close()
|
||||||
return nil, maybeWrapQUICClosedError(err)
|
return nil, wrapIfConnectionClosed(err)
|
||||||
}
|
}
|
||||||
if c.config.FastOpen {
|
if c.config.FastOpen {
|
||||||
// Don't wait for the response when fast open is enabled.
|
// Don't wait for the response when fast open is enabled.
|
||||||
@ -195,7 +195,7 @@ func (c *clientImpl) TCP(addr string) (net.Conn, error) {
|
|||||||
ok, msg, err := protocol.ReadTCPResponse(stream)
|
ok, msg, err := protocol.ReadTCPResponse(stream)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = stream.Close()
|
_ = stream.Close()
|
||||||
return nil, maybeWrapQUICClosedError(err)
|
return nil, wrapIfConnectionClosed(err)
|
||||||
}
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
_ = stream.Close()
|
_ = stream.Close()
|
||||||
@ -222,12 +222,14 @@ func (c *clientImpl) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// maybeWrapQUICClosedError checks if the error returned by quic-go
|
// wrapIfConnectionClosed checks if the error returned by quic-go
|
||||||
// indicates that the QUIC connection is permanently closed,
|
// indicates that the QUIC connection has been permanently closed,
|
||||||
// and if so, wraps it with coreErrs.ClosedError.
|
// and if so, wraps the error with coreErrs.ClosedError.
|
||||||
func maybeWrapQUICClosedError(err error) error {
|
// PITFALL: sometimes quic-go has "internal errors" that are not net.Error,
|
||||||
|
// but we still need to treat them as ClosedError.
|
||||||
|
func wrapIfConnectionClosed(err error) error {
|
||||||
netErr, ok := err.(net.Error)
|
netErr, ok := err.(net.Error)
|
||||||
if ok && !netErr.Temporary() {
|
if !ok || !netErr.Temporary() {
|
||||||
return coreErrs.ClosedError{Err: err}
|
return coreErrs.ClosedError{Err: err}
|
||||||
} else {
|
} else {
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user