Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc: use the loopback conn also for GRPCDialOptions #103764

Merged
merged 1 commit into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion pkg/rpc/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,12 @@ type Context struct {

// SetLoopbackDialer configures the loopback dialer function.
func (c *Context) SetLoopbackDialer(loopbackDialFn func(context.Context) (net.Conn, error)) {
if c.ContextOptions.Knobs.NoLoopbackDialer {
// A test has decided it is opting out of the special loopback
// dialing mechanism. Obey it. We already have defined
// loopbackDialFn in that case in NewContext().
return
}
c.loopbackDialFn = loopbackDialFn
}

Expand Down Expand Up @@ -1640,7 +1646,12 @@ const (
func (rpcCtx *Context) GRPCDialOptions(
ctx context.Context, target string, class ConnectionClass,
) ([]grpc.DialOption, error) {
return rpcCtx.grpcDialOptionsInternal(ctx, target, class, tcpTransport)
transport := tcpTransport
if rpcCtx.Config.AdvertiseAddr == target && !rpcCtx.ClientOnly {
// See the explanation on loopbackDialFn for an explanation about this.
transport = loopbackTransport
}
return rpcCtx.grpcDialOptionsInternal(ctx, target, class, transport)
}

// grpcDialOptions produces dial options suitable for connecting to the given target and class.
Expand Down
11 changes: 11 additions & 0 deletions pkg/server/connectivity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ func TestClusterConnectivity(t *testing.T) {
// We're going to manually control initialization in this test.
NoAutoInitializeCluster: true,
StoreSpecs: []base.StoreSpec{{InMemory: true}},
Knobs: base.TestingKnobs{
Server: &server.TestingKnobs{
ContextTestingKnobs: rpc.ContextTestingKnobs{
// Disable the special RPC loopback dial logic.
// This is needed because the test starts to perform
// RPC dials before the PreStart() function is called,
// and that is where the loopback dial function is defined.
NoLoopbackDialer: true,
},
},
},
}

for i, test := range testConfigurations {
Expand Down