From b5381e53bb947e67cb4d3159a8becdb3e25c6aea Mon Sep 17 00:00:00 2001 From: Max Shegai Date: Fri, 14 Jun 2024 06:45:36 -0700 Subject: [PATCH] s426001: don't check RemoteAddr in unix conn Summary: D58133843 changed error conditions. On MacOS Unix Socket connections don't have RemoteAddr set, which led to error (s426001) Reviewed By: awalterschulze Differential Revision: D58582532 fbshipit-source-id: 93f40ebdc7bf115a9de28805fbb611310c2cfe66 --- thrift/lib/go/thrift/socket.go | 4 ++++ thrift/lib/go/thrift/socket_test.go | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/thrift/lib/go/thrift/socket.go b/thrift/lib/go/thrift/socket.go index ff76e9d9360..d197e32ed5a 100644 --- a/thrift/lib/go/thrift/socket.go +++ b/thrift/lib/go/thrift/socket.go @@ -90,6 +90,10 @@ func NewSocket(options ...SocketOption) (net.Conn, error) { } } + if _, ok := socket.conn.(*net.UnixConn); ok { + return socket, nil + } + if socket.conn.RemoteAddr().String() == "" { return nil, errors.New("must supply either an address or a connection") } diff --git a/thrift/lib/go/thrift/socket_test.go b/thrift/lib/go/thrift/socket_test.go index 45aa5a348ed..cf65c6e5c98 100644 --- a/thrift/lib/go/thrift/socket_test.go +++ b/thrift/lib/go/thrift/socket_test.go @@ -17,6 +17,7 @@ package thrift import ( + "net" "runtime" "testing" ) @@ -37,3 +38,24 @@ func TestNewSocket(t *testing.T) { t.Errorf("wrong address: %s", addr) } } + +func TestNewSocketUnix(t *testing.T) { + path := t.TempDir() + "/test.sock" + + l, err := net.Listen("unix", path) + if err != nil { + t.Fatalf("Cannot listen on unix socket %q: %v", path, err) + } + defer l.Close() + + conn, err := net.Dial("unix", path) + if err != nil { + t.Fatalf("Cannot dial unix socket %q: %v", path, err) + } + + s, err := NewSocket(SocketConn(conn)) + if err != nil { + t.Fatalf("Cannot create new socket: %v", err) + } + defer s.Close() +}