Skip to content
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

Merged
merged 2 commits into from
Mar 19, 2024

Conversation

jhump
Copy link
Member

@jhump jhump commented Mar 18, 2024

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.

@jhump jhump requested review from emcfarlane and akshayjshah March 18, 2024 17:10
Copy link
Contributor

@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

Copy link
Member

@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.

Change makes sense to me, just two nits.

connect.go Outdated Show resolved Hide resolved
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.
Copy link
Member

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.

Copy link
Member Author

@jhump jhump Mar 18, 2024

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.

Copy link
Member Author

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?

@jhump jhump merged commit fbcf0ff into main Mar 19, 2024
12 checks passed
@jhump jhump deleted the jh/fix-error-code-for-cardinality-violations branch March 19, 2024 18:43
@jhump jhump added the bug Something isn't working label Mar 20, 2024
@jhump jhump mentioned this pull request Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants