From 7c30c75ec0a2bcb03100a26254264ccb55a1b564 Mon Sep 17 00:00:00 2001 From: guage Date: Tue, 13 Sep 2022 08:37:15 +0800 Subject: [PATCH] fix handleConnect --- request.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/request.go b/request.go index b615fcb..d659c0c 100644 --- a/request.go +++ b/request.go @@ -191,19 +191,21 @@ func (s *Server) handleConnect(ctx context.Context, conn conn, req *Request) err defer target.Close() // Send success - local := target.LocalAddr().(*net.TCPAddr) - bind := AddrSpec{IP: local.IP, Port: local.Port} + bind := AddrSpec{IP: net.IPv4zero, Port: 0} + if local, ok := target.LocalAddr().(*net.TCPAddr); ok { + bind = AddrSpec{IP: local.IP, Port: local.Port} + } if err := sendReply(conn, successReply, &bind); err != nil { return fmt.Errorf("Failed to send reply: %v", err) } // Start proxying - errCh := make(chan error, 2) + errCh := make(chan error, 1) go proxy(target, req.bufConn, errCh) go proxy(conn, target, errCh) // Wait - for i := 0; i < 2; i++ { + for i := 0; i < 1; i++ { e := <-errCh if e != nil { // return from this function closes target (and conn).