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

Added Nil Check for Package in File Descriptor #3223

Closed
wants to merge 2 commits into from
Closed
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
30 changes: 29 additions & 1 deletion lib/netext/grpcext/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,28 @@ func TestResolveFileDescriptors(t *testing.T) {
services: []string{},
expectedDescriptors: 0,
},
{
name: "NoPackage",
services: []string{"Service1", "Service2"},
expectedDescriptors: 2,
},
{
name: "NoPackageDeduplicateServices",
services: []string{"Service1", "Service2", "Service1"},
expectedDescriptors: 2,
},
{
name: "MixPackage",
pkgs: []string{"mypkg1"},
services: []string{"Service1", "Service2"},
expectedDescriptors: 2,
},
{
name: "MixPackageDeduplicateServices",
pkgs: []string{"mypkg1"},
services: []string{"Service1", "Service2", "Service1"},
expectedDescriptors: 2,
},
Comment on lines +192 to +213
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is clear enough in this way because we already use undefined when we want to reuse for all of them. We could use an empty string for defining a no package.

Suggested change
{
name: "NoPackage",
services: []string{"Service1", "Service2"},
expectedDescriptors: 2,
},
{
name: "NoPackageDeduplicateServices",
services: []string{"Service1", "Service2", "Service1"},
expectedDescriptors: 2,
},
{
name: "MixPackage",
pkgs: []string{"mypkg1"},
services: []string{"Service1", "Service2"},
expectedDescriptors: 2,
},
{
name: "MixPackageDeduplicateServices",
pkgs: []string{"mypkg1"},
services: []string{"Service1", "Service2", "Service1"},
expectedDescriptors: 2,
},
{
name: "NoPackage",
pkgs: []string{""},
services: []string{"Service1", "Service2"},
expectedDescriptors: 2,
},
{
name: "NoPackageDeduplicateServices",
pkgs: []string{""},
services: []string{"Service1", "Service2", "Service1"},
expectedDescriptors: 2,
},
{
name: "MixPackage",
pkgs: []string{"mypkg1", ""},
services: []string{"Service1", "Service2"},
expectedDescriptors: 2,
},
{
name: "MixPackageDeduplicateServices",
pkgs: []string{"mypkg1", ""},
services: []string{"Service1", "Service2", "Service1"},
expectedDescriptors: 2,
},

}

for _, tt := range tests {
Expand All @@ -199,10 +221,16 @@ func TestResolveFileDescriptors(t *testing.T) {
lsr = &reflectpb.ListServiceResponse{}
mock = &getServiceFileDescriptorMock{}
)

var pkg string
if len(tt.pkgs) == 1 {
pkg = tt.pkgs[0]
}

Comment on lines +225 to +229
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm for completely removing this, every service should have an equivalent package defined (empty or non-empty), in this way we can remove any eventual confusion.

for i, service := range tt.services {
// if only one package is defined then
// the package is the same for every service
Comment on lines 231 to 232
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// if only one package is defined then
// the package is the same for every service

pkg := tt.pkgs[0]

if len(tt.pkgs) > 1 {
pkg = tt.pkgs[i]
}
Expand Down
8 changes: 6 additions & 2 deletions lib/netext/grpcext/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ func (rc *reflectionClient) resolveServiceFileDescriptors(
if err = proto.Unmarshal(raw, &fdp); err != nil {
return nil, fmt.Errorf("can't unmarshal proto on service %q: %w", service, err)
}

fdkey := fileDescriptorLookupKey{
Package: *fdp.Package,
Name: *fdp.Name,
Name: *fdp.Name,
}
if fdp.Package != nil {
fdkey.Package = *fdp.Package
}

if seen[fdkey] {
// When a proto file contains declarations for multiple services
// then the same proto file is returned multiple times,
Expand Down