-
Notifications
You must be signed in to change notification settings - Fork 4.8k
xds: suppress the duplicate errors at the client side #9185
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 4 commits
35d57a6
0e3ce43
82cbfbb
0306ac0
9db08e2
bc6a797
2e39651
c86b1c1
8b12741
f71e3ab
8e37e64
f392ec8
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 |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import ( | |
| "context" | ||
| "fmt" | ||
| "strings" | ||
| "sync/atomic" | ||
| "testing" | ||
| "time" | ||
|
|
||
|
|
@@ -506,3 +507,97 @@ func (s) TestADS_ACK_NACK_ResourceIsNotRequestedAnymore(t *testing.T) { | |
| t.Fatal(err) | ||
| } | ||
| } | ||
|
|
||
| // TestADS_NACKError_DuplicateSuppression verifies that when a duplicate | ||
|
eshitachandwani marked this conversation as resolved.
Outdated
|
||
| // invalid LDS resource is sent by the server, the client suppresses the | ||
| // duplicate error notification to the watcher. | ||
| // | ||
| // Note: This behavior (suppress duplicate error notifications to watchers) was | ||
| // originally introduced to handle invalid EDS resources (missing localities) as | ||
|
mswierq marked this conversation as resolved.
Outdated
|
||
| // detailed in https://github.com/grpc/grpc-go/issues/8994. Since the duplicate | ||
| // suppression mechanism is generic and implemented at the authority/resource-independent | ||
| // level, it is verified here using LDS to avoid registering additional mocked | ||
| // resource types. | ||
| func (s) TestADS_NACKError_DuplicateSuppression(t *testing.T) { | ||
| nackReceivedCh := testutils.NewChannelWithSize(1) | ||
| var nackCount atomic.Int32 | ||
|
Contributor
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. Why do we need an atomic here?
Contributor
Author
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. we don't, I have changed that to a regular int |
||
| mgmtServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{ | ||
| OnStreamRequest: func(_ int64, req *v3discoverypb.DiscoveryRequest) error { | ||
| if req.GetTypeUrl() != xdsresource.V3ListenerURL { | ||
| return nil | ||
| } | ||
| if req.GetErrorDetail() != nil { | ||
|
eshitachandwani marked this conversation as resolved.
|
||
| if count := nackCount.Add(1); count >= 3 { | ||
| nackReceivedCh.Send(nil) | ||
|
mswierq marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
| return nil | ||
| }, | ||
| }) | ||
|
|
||
| const listenerName = "listener" | ||
| nodeID := uuid.New().String() | ||
|
|
||
| // Create an xDS client pointing to the above server. | ||
| configs := map[string]grpctransport.Config{"insecure": {Credentials: insecure.NewBundle()}} | ||
| client := createXDSClient(t, mgmtServer.Address, nodeID, grpctransport.NewBuilder(configs)) | ||
|
|
||
| // Use a custom watcher that counts invocations. | ||
| errCh := testutils.NewChannelWithSize(1) | ||
| watcher := &countingListenerWatcher{errCh: errCh} | ||
| ldsCancel := client.WatchResource(xdsresource.V3ListenerURL, listenerName, watcher) | ||
| defer ldsCancel() | ||
|
|
||
| resources := e2e.UpdateOptions{ | ||
| NodeID: nodeID, | ||
| Listeners: []*v3listenerpb.Listener{badListenerResource(t, listenerName)}, | ||
| SkipValidation: true, | ||
| } | ||
| ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) | ||
| defer cancel() | ||
| if err := mgmtServer.Update(ctx, resources); err != nil { | ||
| t.Fatalf("Failed to update management server with resources: %v, err: %v", resources, err) | ||
| } | ||
|
|
||
| // Verify that the watcher receives the initial error. | ||
| v, err := errCh.Receive(ctx) | ||
| if err != nil { | ||
| t.Fatalf("timeout when waiting for an endpoints resource error from the management server: %v", err) | ||
|
Contributor
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. Here and elsewhere in this PR: Please see https://google.github.io/styleguide/go/decisions#error-strings where it talks about the common recommendation of starting error strings with a lowercase alphabet does not apply to test failures.
Contributor
Author
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. fixed |
||
| } | ||
| gotErr := v.(error) | ||
| wantNackErr := "no RouteSpecifier" | ||
|
easwars marked this conversation as resolved.
Outdated
|
||
| if !strings.Contains(gotErr.Error(), wantNackErr) { | ||
|
easwars marked this conversation as resolved.
Outdated
|
||
| t.Fatalf("update received with error: %v, want %q", gotErr, wantNackErr) | ||
| } | ||
|
|
||
| // Wait for the management server to receive at least 3 NACKs, indicating that | ||
| // the NACK resend loop has run multiple times. | ||
| if _, err := nackReceivedCh.Receive(ctx); err != nil { | ||
| t.Fatalf("timeout waiting for 3 NACKs to be received by the server: %v", err) | ||
| } | ||
|
|
||
| // Verify that the count of error callbacks is still exactly 1, proving that | ||
| // subsequent duplicate error updates were suppressed. | ||
| if count := watcher.errCount.Load(); count != 1 { | ||
| t.Fatalf("Error callback invoked %d times, want 1", count) | ||
| } | ||
|
easwars marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| type countingListenerWatcher struct { | ||
| errCh *testutils.Channel | ||
| errCount atomic.Int32 | ||
| } | ||
|
|
||
| func (*countingListenerWatcher) ResourceChanged(_ xdsclient.ResourceData, done func()) { | ||
| done() | ||
| } | ||
| func (c *countingListenerWatcher) ResourceError(err error, done func()) { | ||
| c.errCount.Add(1) | ||
| c.errCh.Send(err) | ||
| done() | ||
| } | ||
| func (c *countingListenerWatcher) AmbientError(err error, done func()) { | ||
| c.errCount.Add(1) | ||
| c.errCh.Send(err) | ||
| done() | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.