grpc-reflection doesn't load properly when an imported type doesn't have a package

オープン
#2,934 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@matrosovs がすでに取り組んでいます。

2025年4月10日 から。

  • #2941 @matrosovs による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
node.js, typescript
領域
api, backend, testing

調査の方向性

packages/grpc-reflection/src/implementations/reflection-v1.ts から始め、インポートされた型に package がない場合に参照されたシンボルがどのように解決されるかを調べます。examples/protos/helloworld.proto と examples/protos/nopackage.proto を使ってケースを再現し、その後 packages/grpc-reflection/test/test-reflection-v1-implementation.ts と動作を比較します。NoPackage 警告なしで reflection がサービス定義を読み込み、このケースをカバーする回帰テストがあれば完了です。

索引モデルが issue の本文から書いたものです。

説明

package: @grpc/reflection
Problem description

When imported type doesn't have a package, and it is used as a field, when I try to enable reflection, first I get these warnings:

Could not find file associated with reference NoPackage

But the gRPC service starts succesfully. However, when trying to load the service definition in Postman I get this error:

Image

Reproduction steps

I modified your reflection example to simulate the problem we have in our code. Please check here. See these 2 files:

  • examples/protos/helloworld.proto
  • examples/protos/nopackage.proto

This is what I get when I run it:

$ node ./reflection/server.js 
Debugger listening on ws://127.0.0.1:53801/5014bd58-6641-4daa-a11b-f7b03f82abcb
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Could not find file associated with reference NoPackage  <--- these are the warnings in question
Could not find file associated with reference NoPackage
(node:141961) DeprecationWarning: Calling start() is no longer necessary. It can be safely omitted.
(Use `node --trace-deprecation ...` to show where the warning was created)

And if I try to load the definition via reflection in postman, I will get the error on the screenshot above.

Environment
  • OS name, version and architecture: Debian GNU/Linux 12 (bookworm), AMD x64
  • Node version: v20.18.0
  • Node installation method: for this particular example I used npm, but in our project we use yarn
  • Package name and version: @grpc/[email protected]
Additional context

This seem related to this issue: https://github.com/grpc/grpc-node/issues/2671, but sort of in reverse. Instead of removing the dot, I need to add one.

The way I resolved it is by simply checking if there is a reference with a leading dot. See packages/grpc-reflection/src/implementations/reflection-v1.ts in the same branch:

        // if we didn't find anything then try just a FQN lookup
        if (!referencedFile) {
          referencedFile = this.symbols[ref] ?? this.symbols[`.${ref}`];
        }

I would have opened a PR with my change, but I am not sure how to test it. I tried to add a test to packages/grpc-reflection/test/test-reflection-v1-implementation.ts (and updated *.proto files to have the same setup), but regardless of whether this fix is present or not, I get the same content for reflectionService.

But if you rerun the example service with the fix, definition loads via reflection with no issues:
Image

And Postman can even generate some sample request:
Image

主要言語
TypeScript
スター
4.8k
フォーク
720
平均マージ
2日 17時間
マージ済み PR(30日)
11

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

grpc/grpc-node のほかの issue

grpc/grpc-node の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。