grpc-reflection doesn't load properly when an imported type doesn't have a package
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- node.js, typescript
調査の方向性
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 の本文から書いたものです。
説明
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:
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.protoexamples/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:
And Postman can even generate some sample request:
- 主要言語
- TypeScript
- スター
- 4.8k
- フォーク
- 720
- 平均マージ
- 2日 17時間
- マージ済み PR(30日)
- 11
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
grpc/grpc-node のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
grpc/grpc-node#3112 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
CompressionFilter’s IdentityHandler.writeMessage calls Buffer-only .copy() on caller-provided message対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
package: @grpc/grpc-js
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
grpc/grpc-node#2993 · コメント 3 件 · リアクション 5 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
Remove unused dependencies対応中かも @alastair-smith が今日担当しました。 オープンchore other
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
alastair-smith/card-games#384 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
code-yeongyu/senpi#5571 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
nexu-io/open-design#9262 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
friction
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
kentcdodds/kody#4753 ·
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
難易度 1/5 1時間未満 初心者へのやさしさ 62/100
lingdojo/kana-dojo#33508 · コメント 1 件 · リアクション 5 件 ·
メンテナーはふだん 1 日以内に返信