Skip to content

Conversation

@jhump
Copy link
Member

@jhump jhump commented Nov 10, 2023

The original motivation for this change was to mirror the fix in grpc/grpc-go#6771. (See that issue for more context; originally reported as a bug against recent version of grpcurl.)

The issue there is that "placeholder" files (see Descriptor.IsPlaceholder) would be serialized as invalid descriptor protos (related). But they really shouldn't be serialized at all: they represent missing dependencies, so it's better to elide them.

While writing new tests for this, I also discovered that we were caching sent files incorrectly. The code was using FileDescriptor.FullName which is sadly not really specified in the docs. In practice, this returns the file's package, which is not enough to uniquely identify a file. That means we would only send back one dependency per package (instead of the entire graph), and then require the client ask for the others one-at-a-time. So this branch fixes that, too.

@jhump jhump requested a review from akshayjshah November 10, 2023 21:51
Copy link
Collaborator

@emcfarlane emcfarlane left a comment

Choose a reason for hiding this comment

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

lgtm! The FullName for file descriptor is a great catch.

grpcreflect.go Outdated
}

func (s *fileDescriptorNameSet) Insert(fd protoreflect.FileDescriptor) {
func (s *fileDescriptorNameSet) Insert(path string) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: fileDescriptorNameSet use to take an fd. It looks like it changed to a path for testing. Maybe could keep the fd and the tests reference the fd too to make it clear that FullName wasn't unique. Otherwise this is a generic string set type.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps this could be a set of type pather interface { Path() string }? I do like the fact that the existing code keeps the set type a little higher-level - it'd be nice to preserve that. In tests, we could implement the pather interface with type path string. That also leaves a clear place to document that FullName isn't unique.

Copy link
Member Author

Choose a reason for hiding this comment

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

Alright. I just changed the signatures back to protoreflect.FileDescriptor and then added a dummyFile implementation that the test can use for this.

Copy link
Contributor

@akshayjshah akshayjshah left a comment

Choose a reason for hiding this comment

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

Fine with me as-is, but if it's not too cumbersome I also liked having the set operate on descriptors.

grpcreflect.go Outdated
}

func (s *fileDescriptorNameSet) Insert(fd protoreflect.FileDescriptor) {
func (s *fileDescriptorNameSet) Insert(path string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps this could be a set of type pather interface { Path() string }? I do like the fact that the existing code keeps the set type a little higher-level - it'd be nice to preserve that. In tests, we could implement the pather interface with type path string. That also leaves a clear place to document that FullName isn't unique.

Copy link
Member Author

Choose a reason for hiding this comment

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

FYI, these changes were made by Go 1.21. I recently updated Go to this latest version on my laptop, and it made these changes when running make test lint.

@jhump jhump merged commit fcedb69 into main Nov 14, 2023
@jhump jhump deleted the jh/omit-placeholders branch November 14, 2023 17:10
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.

4 participants