Use "unimplemented" code for cardinality violations#712
Merged
Conversation
akshayjshah
approved these changes
Mar 18, 2024
Contributor
akshayjshah
left a comment
There was a problem hiding this comment.
Change makes sense to me, just two nits.
connect.go
Outdated
| // trailers, try to read another message from the stream. | ||
| // In a well-formed stream, the one message must be the only content in the body. | ||
| // To verify that it is well-formed, try to read another message from the stream. | ||
| // TODO: optimise unary calls to avoid this extra receive. |
Contributor
There was a problem hiding this comment.
This TODO should be removed now, right? We always want to check stream cardinality.
Member
Author
There was a problem hiding this comment.
I interpreted the comment as wanting this second call to be more efficient. Currently, it requires allocating the second message, trying to fully read the subsequent message on the stream, and unmarshalling the data into the message. An optimized flow could do something cheaper and allocation-free to verify whether it has reached the end of stream or not.
Member
Author
There was a problem hiding this comment.
I revised the comment. Seem okay?
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The table in the docs for gRPC status codes indicates that a "cardinality violation" -- when a stream is expected to have exactly one message and instead has zero or multiple -- should result in an "unimplemented" error code, both from clients upon observing a malformed response stream and from servers upon observing a malformed request stream.
This library was previously using "unknown" as the error code, fashioned after grpc-go, which apparently does not correctly implement this. Further, this library only validated the response stream, in the client. With this change, it uses the correct code and also validates the request stream, in the server.