-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use "unimplemented" code for cardinality violations #712
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change makes sense to me, just two nits.
connect.go
Outdated
// of in-stream trailers or HTTP trailers. To ensure that we receive the | ||
// 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This TODO should be removed now, right? We always want to check stream cardinality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I revised the comment. Seem okay?
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.