From ad48766deaf253d1c01390de4fa5a5c80a2fb8ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Matczuk?= Date: Mon, 12 Feb 2024 15:14:32 +0100 Subject: [PATCH] martian: remove nosigpipe Removing it as it's not used. nosigpipe targets only darwin && go1.9, and it's for mobile i.e. running martian on iPhone. The associated issues are mostly closed, and from 2016/2017. --- internal/martian/nosigpipe/nosigpipe.go | 11 ------ .../martian/nosigpipe/nosigpipe_darwin.go | 38 ------------------- internal/martian/proxy.go | 8 +--- 3 files changed, 1 insertion(+), 56 deletions(-) delete mode 100644 internal/martian/nosigpipe/nosigpipe.go delete mode 100644 internal/martian/nosigpipe/nosigpipe_darwin.go diff --git a/internal/martian/nosigpipe/nosigpipe.go b/internal/martian/nosigpipe/nosigpipe.go deleted file mode 100644 index 9b0af16a..00000000 --- a/internal/martian/nosigpipe/nosigpipe.go +++ /dev/null @@ -1,11 +0,0 @@ -//go:build !darwin || !go1.9 -// +build !darwin !go1.9 - -package nosigpipe - -import "net" - -// IgnoreSIGPIPE prevents SIGPIPE from being raised on TCP sockets when remote hangs up -// See: https://github.com/golang/go/issues/17393. Do nothing for non Darwin. -func IgnoreSIGPIPE(_ net.Conn) { -} diff --git a/internal/martian/nosigpipe/nosigpipe_darwin.go b/internal/martian/nosigpipe/nosigpipe_darwin.go deleted file mode 100644 index 9682ac61..00000000 --- a/internal/martian/nosigpipe/nosigpipe_darwin.go +++ /dev/null @@ -1,38 +0,0 @@ -//go:build darwin && go1.9 -// +build darwin,go1.9 - -package nosigpipe - -import ( - "context" - "net" - "syscall" - - "github.com/saucelabs/forwarder/internal/martian/log" -) - -// IgnoreSIGPIPE prevents SIGPIPE from being raised on TCP sockets when remote hangs up -// See: https://github.com/golang/go/issues/17393 -func IgnoreSIGPIPE(c net.Conn) { - if c == nil { - return - } - s, ok := c.(syscall.Conn) - if !ok { - return - } - r, e := s.SyscallConn() - if e != nil { - log.Errorf(context.TODO(), "Failed to get SyscallConn: %s", e) - return - } - e = r.Control(func(fd uintptr) { - intfd := int(fd) - if e := syscall.SetsockoptInt(intfd, syscall.SOL_SOCKET, syscall.SO_NOSIGPIPE, 1); e != nil { - log.Errorf(context.TODO(), "Failed to set SO_NOSIGPIPE: %s", e) - } - }) - if e != nil { - log.Errorf(context.TODO(), "Failed to set SO_NOSIGPIPE: %s", e) - } -} diff --git a/internal/martian/proxy.go b/internal/martian/proxy.go index 7d9b1e88..2e2e075d 100644 --- a/internal/martian/proxy.go +++ b/internal/martian/proxy.go @@ -27,7 +27,6 @@ import ( "github.com/saucelabs/forwarder/internal/martian/log" "github.com/saucelabs/forwarder/internal/martian/mitm" - "github.com/saucelabs/forwarder/internal/martian/nosigpipe" "github.com/saucelabs/forwarder/internal/martian/proxyutil" "golang.org/x/net/http/httpguts" ) @@ -172,11 +171,7 @@ func (p *Proxy) SetUpstreamProxyFunc(f func(*http.Request) (*url.URL, error)) { // SetDialContext sets the dial func used to establish a connection. func (p *Proxy) SetDialContext(dial func(context.Context, string, string) (net.Conn, error)) { - p.dial = func(ctx context.Context, network, addr string) (net.Conn, error) { - c, e := dial(ctx, network, addr) - nosigpipe.IgnoreSIGPIPE(c) - return c, e - } + p.dial = dial if tr, ok := p.roundTripper.(*http.Transport); ok { tr.DialContext = p.dial @@ -221,7 +216,6 @@ func (p *Proxy) Serve(l net.Listener) error { } conn, err := l.Accept() - nosigpipe.IgnoreSIGPIPE(conn) if err != nil { var nerr net.Error if ok := errors.As(err, &nerr); ok && nerr.Temporary() {