Skip to content

Fix self-referencing file dependency - #91

Merged
mjheilmann merged 3 commits into
elixir-grpc:mainfrom
zhihuizhang17:fix/self-referencing-file-dependency
Nov 10, 2026
Merged

mjheilmann merged 3 commits into
elixir-grpc:mainfrom
zhihuizhang17:fix/self-referencing-file-dependency

Conversation

@zhihuizhang17

Copy link
Copy Markdown
Contributor

Fixes #90

A message that refers to itself, or a nested type that refers back to its enclosing message, left its file listed in its own dependency. shrink_cycles only merges cycles of two or more files, so nothing removed it. A client resolves every dependency before using a file, so grpcurl overflowed its stack.

Drop a file's own name from its dependencies in Builder.resolve_dependencies/1.

Tests

  • New self_reference fixture: a self-referencing message (also through a repeated field) and a nested type that points back at its parent.
  • test/case/self_reference_test.exs runs against v1 and v1alpha: lists the service, asserts no file depends on itself, and traverses the graph with grpcurl.
  • Without the fix, 4 of the 6 new tests fail (file depends on itself, grpcurl stack overflow). With it, the full suite passes (212 tests, 0 failures).

🤖 Generated with Claude Code

A message that refers to itself, or a nested type that refers back to its
enclosing message, left the file listed in its own dependencies, because
shrink_cycles only merges cycles of two or more files. A client resolves
every dependency before using a file, so grpcurl overflowed its stack.

Drop a file's own name from its dependencies in resolve_dependencies.
Adds a self_reference fixture and tests (see elixir-grpc#90).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@mjheilmann mjheilmann left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks pretty good, thanks!

I see this only covers the "descriptor is present" code path, but grpc-reflection now also generates the descriptor payload to enable reflection when the protos schema is compiled without descriptors. I would appreciate it if you covered that case as well in this PR, but I can also do a followup and cover it myself if you cannot.

Take a peek at test/case/no_descriptor/recursive_message_test.exs and the NoDescriptor.* modules to see how we currently test that code path.

Just let me know whether to keep this PR open and to expect those changes from your side, or if I can merge this and then close the descriptor-less gaps myself before making a patch release. Thanks again.

Comment thread lib/grpc_reflection/service/builder.ex Resolved
zhihuizhang17 and others added 2 commits November 10, 2026 11:34
Run the self-reference case against the NoDescriptor modules too. The
nested back-reference case moves to its own proto and is skipped in the
descriptor-less pass: the synthesizer does not support nested messages
yet, so that case fails regardless of this fix.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@zhihuizhang17

Copy link
Copy Markdown
Contributor Author

This looks pretty good, thanks!

I see this only covers the "descriptor is present" code path, but grpc-reflection now also generates the descriptor payload to enable reflection when the protos schema is compiled without descriptors. I would appreciate it if you covered that case as well in this PR, but I can also do a followup and cover it myself if you cannot.

Take a peek at test/case/no_descriptor/recursive_message_test.exs and the NoDescriptor.* modules to see how we currently test that code path.

Just let me know whether to keep this PR open and to expect those changes from your side, or if I can merge this and then close the descriptor-less gaps myself before making a patch release. Thanks again.

The descriptor-less coverage is pushed: a NoDescriptor.SelfReference case that mirrors the recursive_message one. Without the fix it fails the same way (the file lists itself as a dependency).

One thing I ran into: the descriptor-less path doesn't support nested messages yet. The synthesizer emits nested types as top-level messages, so a field still points at pkg.Outer.Inner while the file defines pkg.Inner, and grpcurl fails with cannot resolve type ... not found (the server replies OK). That is separate from this fix. I moved the nested back-reference case to its own proto and skipped it in the descriptor-less pass (noted in mix.exs). Let me know if you'd like it tracked in a separate issue.

@mjheilmann

Copy link
Copy Markdown
Collaborator

That is separate from this fix.

100% agree. Thanks for pointing this out. I'll get this merged, and open a new issue around that problem. Issue created at #92 to track

@mjheilmann
mjheilmann merged commit 32e240f into elixir-grpc:main Nov 10, 2026
11 checks passed
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.

grpcurl stack overflow when a message refers to itself (file lists itself as dependency)

2 participants