Skip to content
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
17 changes: 10 additions & 7 deletions internal/xds/clients/xdsclient/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,7 @@ func (xc *xdsChannel) onResponse(resp response, onDone func()) ([]string, error)
return nil, xdsresource.NewErrorf(xdsresource.ErrorTypeResourceTypeUnsupported, "Resource type URL %q unknown in response from server", resp.typeURL)
}

// Decode the resources and build the list of resource names to return.
opts := &DecodeOptions{
Config: xc.clientConfig,
ServerConfig: xc.serverConfig,
}
updates, md, err := decodeResponse(opts, &rType, resp)
updates, md, err := xc.decodeResponse(&rType, resp)
var names []string
for name := range updates {
names = append(names, name)
Expand All @@ -243,12 +238,16 @@ func (xc *xdsChannel) onResponse(resp response, onDone func()) ([]string, error)
// If there are any errors decoding the resources, the metadata will indicate
// that the update was NACKed, and the returned error will contain information
// about all errors encountered by this function.
func decodeResponse(opts *DecodeOptions, rType *ResourceType, resp response) (map[string]dataAndErrTuple, xdsresource.UpdateMetadata, error) {
func (xc *xdsChannel) decodeResponse(rType *ResourceType, resp response) (map[string]dataAndErrTuple, xdsresource.UpdateMetadata, error) {
timestamp := time.Now()
md := xdsresource.UpdateMetadata{
Version: resp.version,
Timestamp: timestamp,
}
opts := &DecodeOptions{
Config: xc.clientConfig,
ServerConfig: xc.serverConfig,
}

topLevelErrors := make([]error, 0) // Tracks deserialization errors, where we don't have a resource name.
perResourceErrors := make(map[string]error) // Tracks resource validation errors, where we have a resource name.
Expand All @@ -268,6 +267,10 @@ func decodeResponse(opts *DecodeOptions, rType *ResourceType, resp response) (ma
// Name field of the result is left unpopulated only when resource
// deserialization fails.
name := ""
if result == nil && err == nil {
xc.logger.Errorf("Decode() returned nil result and nil error for resource: %v", r)
continue
}
if result != nil {
name = xdsresource.ParseName(result.Name).String()
}
Expand Down
6 changes: 4 additions & 2 deletions internal/xds/clients/xdsclient/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,8 @@ func (s) TestDecodeResponse_PanicRecoveryEnabled(t *testing.T) {
resp := response{resources: []*anypb.Any{{Value: []byte("test")}}}
wantErr := "recovered from panic during resource parsing"

if _, _, err := decodeResponse(&DecodeOptions{}, rType, resp); err == nil || !strings.Contains(err.Error(), wantErr) {
xc := &xdsChannel{}
if _, _, err := xc.decodeResponse(rType, resp); err == nil || !strings.Contains(err.Error(), wantErr) {
t.Fatalf("decodeResponse() failed with err: %v, want %q", err, wantErr)
}
}
Expand All @@ -809,11 +810,12 @@ func (s) TestDecodeResponse_PanicRecoveryDisabled(t *testing.T) {
}
resp := response{resources: []*anypb.Any{{Value: []byte("test")}}}
wantErr := "simulate panic"
xc := &xdsChannel{}

defer func() {
if r := recover(); r == nil || !strings.Contains(fmt.Sprint(r), wantErr) {
t.Fatalf("Expected panic in decodeResponse, got: %v, want: %q", r, wantErr)
}
}()
decodeResponse(&DecodeOptions{}, rType, resp)
xc.decodeResponse(rType, resp)
}
Loading
Loading