mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-09-20 23:14:21 +00:00
The same-host gRPC fast path registered /tmp/...sock paths and dialed
them with net.Listen("unix", ...) / net.Dial("unix", ...). Those paths
are POSIX-only, so on Windows the listener failed at startup and every
local gRPC call routed through the registered port lost its transport.
Gate RegisterLocalGrpcSocket to return early on Windows. ServeGrpcOnLocalSocket
and resolveLocalGrpcSocket already short-circuit when no socket is registered,
so all same-host RPCs fall back to TCP without touching any callsite.
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -81,7 +82,15 @@ func init() {
|
||||
// GrpcDial to host:grpcPort (or to a loopback alias of host on the same
|
||||
// port) is routed through the Unix socket. Dials to any other host on the
|
||||
// same port still go over TCP.
|
||||
//
|
||||
// No-op on Windows: the /tmp/...sock paths callers pass are POSIX-only and
|
||||
// the listen/dial would fail at runtime, taking gRPC down with it (#9430).
|
||||
// Skipping registration leaves the maps empty, so ServeGrpcOnLocalSocket
|
||||
// and resolveLocalGrpcSocket short-circuit and same-host RPCs go over TCP.
|
||||
func RegisterLocalGrpcSocket(host string, grpcPort int, socketPath string) {
|
||||
if runtime.GOOS == "windows" {
|
||||
return
|
||||
}
|
||||
localGrpcSocketsLock.Lock()
|
||||
defer localGrpcSocketsLock.Unlock()
|
||||
localGrpcSockets[grpcPort] = socketPath
|
||||
|
||||
@@ -2,6 +2,7 @@ package pb
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
@@ -74,6 +75,9 @@ func TestIsClientSideMarshalError_RequiresGrpcStatus(t *testing.T) {
|
||||
// continue out over TCP — they must NOT be hijacked into host A's local
|
||||
// socket on the basis of port match alone.
|
||||
func TestResolveLocalGrpcSocket_RemotePortCollision(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("Unix-socket routing is disabled on Windows (#9430)")
|
||||
}
|
||||
// Snapshot and restore global state so the test does not leak into others.
|
||||
localGrpcSocketsLock.Lock()
|
||||
prevSockets := localGrpcSockets
|
||||
|
||||
Reference in New Issue
Block a user