-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
The package specifier is optional in protobuf spec https://protobuf.dev/programming-guides/proto3/#packages This code is to guard against this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Sorry for the slow review 🙇 .
Due to vacations across the team and the automatic assigning not taking this into account, sometimes things get assigned to people who are on vacation :(.
Unfortunately we are also at the end of the development cycle and have some higher priorities things we want to make certain do work for v0.46.0.
The fix seems pretty safe and I can't see any problems with it, but I still prefer if @olegbespalov gives it a 👍 specifically. This might mean that we do merge this in the codefreeze, but given the size and the fact it is a bug that doesn't seem like that much of a problem.
@tmulkern Can you please add a small test that panics without this change though.
Also we will need forward/backport this to xk6-grpc.
I will move this back to v0.46.0 milestone for now, but I can't promise we will actually make it :(
Thanks for the bug report and fix 🙇 And once again sorry for the slow reply
@mstoykov no problem on the response, I am in the same situation myself in my day job, it is the time for Vacations!! |
Regarding the test, no problem in creating, but do we have a GRPC Test Service/Mock Service that I can reference. I couldn't find any. I am not that familiar with the code base, so I could be blind to it ;-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @tmulkern,
thanks for your contribution. 🙇
Regarding the test, no problem in creating, but do we have a GRPC Test Service/Mock Service that I can reference
I guess it should be enough to add a new test case to the following test table. I think we should cover also the case with clashing names now that we are skipping the package.
k6/lib/netext/grpcext/conn_test.go
Line 160 in 3c006a5
func TestResolveFileDescriptors(t *testing.T) { |
Added tests for following scenarios * Services with no package - "NoPackage" * Services with no package and duplicated - "NoPackageDeduplicateServices" * One services with a package, one without - "MixPackage" * Two services with a package (Duplicate), one without - "MixPackageDeduplicateServices" Also updated the TestResolveFileDescriptors to handle cases with no packages
Hey @codebien Added tests for following scenarios
Also updated the TestResolveFileDescriptors to handle cases with no packages |
{ | ||
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, | ||
}, |
There was a problem hiding this comment.
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.
{ | |
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, | |
}, |
var pkg string | ||
if len(tt.pkgs) == 1 { | ||
pkg = tt.pkgs[0] | ||
} | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, in that particular case, I'm more up for keeping the logic (with the comment), like
pkg := ""
// if only one package is defined then
// the package is the same for every service
if len(tt.pkgs) == 1 {
pkg = tt.pkgs[0]
}
The rationale is that having the empty strings confuses me more than the logic of the comment.
// if only one package is defined then | ||
// the package is the same for every service |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// if only one package is defined then | |
// the package is the same for every service |
Applogies people for the late reply, as mstoykov alluded to it is vacation season and I was away on vacation. I will look into coming up with a commit to the test based on your comments |
Hi @tmulkern ! I am sharing this here for the sake of transparency. We have another PR related to the support of gRPC's reflection v1. I believe that PR also fixes the issue that you reported. So we will probably close this PR in favor of #3338. Anyway, thank you for reporting and contribution! 🙇 |
Hey olegbespalov, thank's for the update. Sorry, life got in the way the 2 months and I hadn't got round to finishing this PR. |
What?
This code is to guard against a
runtime error: invalid memory address or nil pointer dereference
occuringWhy?
The package specifier is optional in protobuf spec https://protobuf.dev/programming-guides/proto3/#packages
Checklist
make ci-like-lint
) and all checks pass. N/Amake tests
) and all tests pass. N/ARelated PR(s)/Issue(s)
Fixes issue #3222