-
Notifications
You must be signed in to change notification settings - Fork 4.5k
grpc: move to TransientFailure
in pick_first
LB policy when all addresses are removed
#5274
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,6 @@ import ( | |
"google.golang.org/grpc" | ||
"google.golang.org/grpc/attributes" | ||
"google.golang.org/grpc/balancer" | ||
"google.golang.org/grpc/balancer/roundrobin" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/connectivity" | ||
"google.golang.org/grpc/credentials" | ||
|
@@ -683,87 +682,6 @@ func (s) TestServersSwap(t *testing.T) { | |
} | ||
} | ||
|
||
// TestEmptyAddrs verifies client behavior when a working connection is | ||
// removed. In pick first and round-robin, both will continue using the old | ||
// connections. | ||
Comment on lines
-686
to
-688
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make sure there's still a test for this set of circumstances, but that the RPCs begin failing instead of keep using old connections. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I thought we confirmed RR was removing the subconns, so RPCs should have been failing? But this test is validating the RPCs would still succeed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, this test was quite broken because it was using the pick_first clientConn to verify round_robin behaviour: // Confirm several new RPCs succeed on round robin.
for i := 0; i < 10; i++ {
if _, err := pfclient.UnaryCall(ctx, &testpb.SimpleRequest{}); err != nil {
t.Fatalf("UnaryCall(_) = _, %v; want _, nil", err)
}
time.Sleep(5 * time.Millisecond)
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, the newly added test verifies that the channel moves to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Oof There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
But only with pick first -- is there one for RR too elsewhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
func (s) TestEmptyAddrs(t *testing.T) { | ||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
defer cancel() | ||
|
||
// Initialize server | ||
lis, err := net.Listen("tcp", "localhost:0") | ||
if err != nil { | ||
t.Fatalf("Error while listening. Err: %v", err) | ||
} | ||
s := grpc.NewServer() | ||
defer s.Stop() | ||
const one = "1" | ||
ts := &funcServer{ | ||
unaryCall: func(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) { | ||
return &testpb.SimpleResponse{Username: one}, nil | ||
}, | ||
} | ||
testpb.RegisterTestServiceServer(s, ts) | ||
go s.Serve(lis) | ||
|
||
// Initialize pickfirst client | ||
pfr := manual.NewBuilderWithScheme("whatever") | ||
|
||
pfr.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: lis.Addr().String()}}}) | ||
|
||
pfcc, err := grpc.DialContext(ctx, pfr.Scheme()+":///", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(pfr)) | ||
if err != nil { | ||
t.Fatalf("Error creating client: %v", err) | ||
} | ||
defer pfcc.Close() | ||
pfclient := testpb.NewTestServiceClient(pfcc) | ||
|
||
// Confirm we are connected to the server | ||
if res, err := pfclient.UnaryCall(ctx, &testpb.SimpleRequest{}); err != nil || res.Username != one { | ||
t.Fatalf("UnaryCall(_) = %v, %v; want {Username: %q}, nil", res, err, one) | ||
} | ||
|
||
// Remove all addresses. | ||
pfr.UpdateState(resolver.State{}) | ||
|
||
// Initialize roundrobin client | ||
rrr := manual.NewBuilderWithScheme("whatever") | ||
|
||
rrr.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: lis.Addr().String()}}}) | ||
|
||
rrcc, err := grpc.DialContext(ctx, rrr.Scheme()+":///", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(rrr), | ||
grpc.WithDefaultServiceConfig(fmt.Sprintf(`{ "loadBalancingConfig": [{"%v": {}}] }`, roundrobin.Name))) | ||
if err != nil { | ||
t.Fatalf("Error creating client: %v", err) | ||
} | ||
defer rrcc.Close() | ||
rrclient := testpb.NewTestServiceClient(rrcc) | ||
|
||
// Confirm we are connected to the server | ||
if res, err := rrclient.UnaryCall(ctx, &testpb.SimpleRequest{}); err != nil || res.Username != one { | ||
t.Fatalf("UnaryCall(_) = %v, %v; want {Username: %q}, nil", res, err, one) | ||
} | ||
|
||
// Remove all addresses. | ||
rrr.UpdateState(resolver.State{}) | ||
|
||
// Confirm several new RPCs succeed on pick first. | ||
for i := 0; i < 10; i++ { | ||
if _, err := pfclient.UnaryCall(ctx, &testpb.SimpleRequest{}); err != nil { | ||
t.Fatalf("UnaryCall(_) = _, %v; want _, nil", err) | ||
} | ||
time.Sleep(5 * time.Millisecond) | ||
} | ||
|
||
// Confirm several new RPCs succeed on round robin. | ||
for i := 0; i < 10; i++ { | ||
if _, err := pfclient.UnaryCall(ctx, &testpb.SimpleRequest{}); err != nil { | ||
t.Fatalf("UnaryCall(_) = _, %v; want _, nil", err) | ||
} | ||
time.Sleep(5 * time.Millisecond) | ||
} | ||
} | ||
|
||
func (s) TestWaitForReady(t *testing.T) { | ||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
defer cancel() | ||
|
Uh oh!
There was an error while loading. Please reload this page.