Skip to content

Use "unimplemented" code for cardinality violations#712

Merged
jhump merged 2 commits intomainfrom
jh/fix-error-code-for-cardinality-violations
Mar 19, 2024
Merged

Use "unimplemented" code for cardinality violations#712
jhump merged 2 commits intomainfrom
jh/fix-error-code-for-cardinality-violations

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 akshayjshah and emcfarlane 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
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.

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.
Copy link
Contributor

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