Skip to content

Commit

Permalink
s426001: don't check RemoteAddr in unix conn
Browse files Browse the repository at this point in the history
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
  • Loading branch information
n-canter authored and facebook-github-bot committed Jun 14, 2024
1 parent 1d18a34 commit b5381e5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions thrift/lib/go/thrift/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
22 changes: 22 additions & 0 deletions thrift/lib/go/thrift/socket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package thrift

import (
"net"
"runtime"
"testing"
)
Expand All @@ -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()
}

0 comments on commit b5381e5

Please sign in to comment.