mirror of
https://github.com/cmz0228/hysteria-dev.git
synced 2025-06-08 13:29:53 +00:00
forwarder: better pipe error handling
This commit is contained in:
parent
246c2ce89c
commit
f0c647004f
@ -187,14 +187,21 @@ func (c *QUICClient) handleConn(conn net.Conn) {
|
||||
return
|
||||
}
|
||||
defer stream.Close()
|
||||
// From TCP to QUIC
|
||||
// Pipes
|
||||
errChan := make(chan error, 2)
|
||||
go func() {
|
||||
_ = utils.Pipe(conn, stream, &c.outboundBytes)
|
||||
// TCP to QUIC
|
||||
errChan <- utils.Pipe(conn, stream, &c.outboundBytes)
|
||||
_ = conn.Close()
|
||||
_ = stream.Close()
|
||||
}()
|
||||
// From QUIC to TCP
|
||||
err = utils.Pipe(stream, conn, &c.inboundBytes)
|
||||
// Closed
|
||||
go func() {
|
||||
// QUIC to TCP
|
||||
errChan <- utils.Pipe(stream, conn, &c.inboundBytes)
|
||||
_ = conn.Close()
|
||||
_ = stream.Close()
|
||||
}()
|
||||
// We only need the first error
|
||||
err = <-errChan
|
||||
c.onTCPConnectionClosed(conn.RemoteAddr(), err)
|
||||
}
|
||||
|
@ -160,14 +160,21 @@ func (s *QUICServer) handleStream(addr net.Addr, name string, stream quic.Stream
|
||||
return
|
||||
}
|
||||
defer tcpConn.Close()
|
||||
// From TCP to QUIC
|
||||
// Pipes
|
||||
errChan := make(chan error, 2)
|
||||
go func() {
|
||||
_ = utils.Pipe(tcpConn, stream, &s.outboundBytes)
|
||||
// TCP to QUIC
|
||||
errChan <- utils.Pipe(tcpConn, stream, &s.outboundBytes)
|
||||
_ = tcpConn.Close()
|
||||
_ = stream.Close()
|
||||
}()
|
||||
// From QUIC to TCP
|
||||
err = utils.Pipe(stream, tcpConn, &s.inboundBytes)
|
||||
// Closed
|
||||
go func() {
|
||||
// QUIC to TCP
|
||||
errChan <- utils.Pipe(stream, tcpConn, &s.inboundBytes)
|
||||
_ = tcpConn.Close()
|
||||
_ = stream.Close()
|
||||
}()
|
||||
// We only need the first error
|
||||
err = <-errChan
|
||||
s.onClientStreamClosed(addr, name, int(stream.StreamID()), err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user