Skip to content

fix(grpc-reflection): try to do FQN lookup with a leading period #2941

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

matrosovs
Copy link

This seems to fix a very specific issue, where if the custom field type doesn't have a package, it breaks the reflection API.

Please see this issue for more information: #2934

I haven't added any tests because I couldn't reproduce the issue using the test setup in test-reflection-v1-implementation.ts.

But I did test it manually, and below you can find my test evidence.

Testing

Pre-requisite: add a new imported message, which doesn't have a package. And make it a field of a request or response, e.g. this diff

Also, here a complete diff in case my branch gets deleted (click to expand)
diff --git a/examples/protos/helloworld.proto b/examples/protos/helloworld.proto
index 7e50d0fc7..48c411c41 100644
--- a/examples/protos/helloworld.proto
+++ b/examples/protos/helloworld.proto
@@ -19,6 +19,8 @@ option java_package = "io.grpc.examples.helloworld";
 option java_outer_classname = "HelloWorldProto";
 option objc_class_prefix = "HLW";
 
+import "nopackage.proto";
+
 package helloworld;
 
 // The greeting service definition.
@@ -32,6 +34,7 @@ service Greeter {
 // The request message containing the user's name.
 message HelloRequest {
   string name = 1;
+  NoPackageMessage no_package = 2;
 }
 
 // The response message containing the greetings
diff --git a/examples/protos/nopackage.proto b/examples/protos/nopackage.proto
new file mode 100644
index 000000000..1a002b576
--- /dev/null
+++ b/examples/protos/nopackage.proto
@@ -0,0 +1,6 @@
+syntax = "proto3";
+
+message NoPackageMessage {
+    int32 code = 1;
+    string message = 2;
+ }
\ No newline at end of file

Without the fix

Running the application

Warnigns are printed at the bottom because the reflection service couldn't find the reference for the message with no package:

$ node --no-deprecation examples/reflection/server.js
Debugger listening on ws://127.0.0.1:53772/97d86ad5-174e-45e9-9d34-7da3b690f67c
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Could not find file associated with reference NoPackageMessage
Could not find file associated with reference NoPackageMessage

Loading service definition via Reflection
Postman fails to load the definition. And in the [Service definitions] tab it shows this error:
image

With the fix

Running the application

Warnings no longer printed:

$ node --no-deprecation examples/reflection/server.js
Debugger listening on ws://127.0.0.1:53953/82c837c2-9c9f-49b4-962e-1d2b7653ee55
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.

Loading service definition via Reflection
Postman can successfully load the definition.
image

Also, it understands the new nested field and can generate some example message.
image

Copy link

linux-foundation-easycla bot commented Apr 10, 2025

CLA Signed


The committers listed above are authorized under a signed CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant