chore(tonic): Move ConnectError type from transport#1828
Merged
djc merged 3 commits intohyperium:masterfrom Aug 1, 2024
Merged
chore(tonic): Move ConnectError type from transport#1828djc merged 3 commits intohyperium:masterfrom
djc merged 3 commits intohyperium:masterfrom
Conversation
By moving the TimeoutExpired type from the transport module
to the the tonic engine proper, the type is made available to
other transport implementations and tonic can be built without
the "server" feature while still returning a Status indicating
the timeout.
Alternative transport implementations can use the type, now that it is
moved, when they want the tonic Status error handling to recognize the
error as having been triggered by a timeout in the transport logic. The
tonic Status error will have a code of Cancelled with a message of
"Timeout expired".
There is already a test for this:
cargo test picks_server_timeout_if_thats_sorter
which worked the original way and contines to work; but now a new
transport implementation can get the same behavior.
Addresses hyperium#1825.
tottoto
approved these changes
Aug 1, 2024
Collaborator
|
Looks good to me. |
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.
Move the ConnectError type from transport to tonic.
Motivation
Making
ConnectErrora tonic type allows the tonic Status to convert a transport generated connection error into a Status::code() of Status::unavailable. As the comment in status.rs already says, this is consistent with the behavior of a C++ gRPC client when the server is not running, and matches the spec.The only other error that results in a Status::unavailable is a timeout error when the crate is built with its 'transport' module, allowing it to recognize when an error is a hyper timeout error. But a possible loosening of that relationship is not being addressed here.
Solution
Move the type from the transport module, where it can only be used by the Status code when tonic is compiled with its own transport, to the status code in tonic itself, so the built in transport can use it and proprietary transports can use it.
There are already two tests that look for this Status::unavailable result. They passed before and they pass with this change as well. (
connect_lazy_reconnects_after_first_failureandconnect_returns_err_via_call_after_connected)