Skip to content

Commit

Permalink
fix: TProxy UDP error log
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyxdd committed Aug 11, 2023
1 parent ceb3c7f commit cbfb199
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions app/internal/tproxy/udp_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,22 @@ func (r *UDPTProxy) newPair(srcAddr, dstAddr *net.UDPAddr, initPkt []byte) {
return
}
// Start forwarding
go r.forwarding(conn, hyConn, dstAddr.String())
go func() {
err := r.forwarding(conn, hyConn, dstAddr.String())
_ = conn.Close()
_ = hyConn.Close()
if r.EventLogger != nil {
var netErr net.Error
if errors.As(err, &netErr) && netErr.Timeout() {
// We don't consider deadline exceeded (timeout) an error
err = nil
}
r.EventLogger.Error(srcAddr, dstAddr, err)
}
}()
}

func (r *UDPTProxy) forwarding(conn *net.UDPConn, hyConn client.HyUDPConn, dst string) {
func (r *UDPTProxy) forwarding(conn *net.UDPConn, hyConn client.HyUDPConn, dst string) error {
errChan := make(chan error, 2)
// Local <- Remote
go func() {
Expand Down Expand Up @@ -116,17 +128,7 @@ func (r *UDPTProxy) forwarding(conn *net.UDPConn, hyConn client.HyUDPConn, dst s
}
}
}()
err := <-errChan
_ = conn.Close()
_ = hyConn.Close()
if r.EventLogger != nil {
var netErr net.Error
if errors.As(err, &netErr) && netErr.Timeout() {
// We don't consider deadline exceeded (timeout) an error
err = nil
}
r.EventLogger.Error(conn.LocalAddr(), conn.RemoteAddr(), err)
}
return <-errChan
}

func (r *UDPTProxy) updateConnDeadline(conn *net.UDPConn) error {
Expand Down

0 comments on commit cbfb199

Please sign in to comment.