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

[devicetrust] fix: handle server errors in bi-directional streams #44677

Merged
merged 3 commits into from
Jul 30, 2024

Conversation

tigrato
Copy link
Contributor

@tigrato tigrato commented Jul 26, 2024

Fix an edge case in the devicetrust gRPC bi-directional stream handler where the stream could terminate with an error after the last client Recv call but before the next Send call. Previously, this scenario caused the Send method to return an io.EOF error, which indicated that the connection was terminated but did not reveal any errors returned by the server. This update ensures that the client continues to consume the stream until an error is returned, allowing for proper error handling and more robust stream management.

Changelog: Ensure Device Trust clients correctly handle server errors on abruptly terminated streams.

// The client only sees the server's error when it tries to read from the stream.
// This function repeatedly calls Recv to surface the first error encountered.
// Use this function when the stream's content is irrelevant and only the error matters.
func consumeStreamToError(sendErr error, stream devicepb.DeviceTrustService_AuthenticateDeviceClient) error {
Copy link
Contributor Author

@tigrato tigrato Jul 26, 2024

Choose a reason for hiding this comment

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

I defined this function 3 times to avoid making any of these functions publicly available in api to avoid people incorrectly using them.

If you guys prefer it to be moved, I am ok with it

Moved to api/utils since there are tons of bad usage in our codebase

Fix an edge case in the devicetrust gRPC bi-directional stream handler where the stream could terminate with an error after the last client `Recv` call but before the next `Send` call.
Previously, this scenario caused the `Send` method to return an `io.EOF` error, which indicated that the connection was terminated but did not reveal any errors returned by the server.
This update ensures that the client continues to consume the stream until an error is returned, allowing for proper error handling and more robust stream management.

Signed-off-by: Tiago Silva <[email protected]>
@tigrato tigrato force-pushed the tigrato/fix-grpc-bi-streaming-err branch from 61e4ff8 to 1d57fab Compare July 26, 2024 13:17
Copy link
Contributor

@codingllama codingllama left a comment

Choose a reason for hiding this comment

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

Thanks, Tiago.

api/utils/stream_consumer.go Outdated Show resolved Hide resolved
api/utils/stream_consumer.go Outdated Show resolved Hide resolved
lib/devicetrust/authn/authn.go Outdated Show resolved Hide resolved
api/utils/stream_consumer.go Outdated Show resolved Hide resolved
@tigrato tigrato enabled auto-merge July 29, 2024 15:14
@public-teleport-github-review-bot public-teleport-github-review-bot bot removed the request for review from camscale July 30, 2024 08:45
@tigrato tigrato added this pull request to the merge queue Jul 30, 2024
Merged via the queue into master with commit cdfed08 Jul 30, 2024
38 checks passed
@tigrato tigrato deleted the tigrato/fix-grpc-bi-streaming-err branch July 30, 2024 09:02
@public-teleport-github-review-bot

@tigrato See the table below for backport results.

Branch Result
branch/v14 Failed
branch/v15 Failed
branch/v16 Failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants