diff --git a/internal/proxy/proxy.go b/internal/proxy/proxy.go index 6dfbf9e..cf91210 100644 --- a/internal/proxy/proxy.go +++ b/internal/proxy/proxy.go @@ -111,11 +111,22 @@ func (p Proxy) ServeTLS(ln net.Listener, certFile, keyFile string) { ln = tls.NewListener(ln, cfg) defer ln.Close() - for { - if err := acceptAndHandle(ln, httpproxy.Handler(d), d); err != nil { - panic(err) + socksListener, httpListener := proxymux.SplitSOCKSAndHTTP(ln) + errc := make(chan error, 2) + go func() { + for { + if err := acceptAndHandle(httpListener, httpproxy.Handler(d), d); err != nil { + errc <- err + } } - } + }() + go func() { + socksProxy := &socks5.Server{Dialer: d} + if err := socksProxy.Serve(socksListener); err != nil { + errc <- err + } + }() + <-errc } type singleListener struct {