set canceled status code if the underlying hyper error was due to cancelation #1669
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.
Motivation
At work we use
tonic
to query CRI sockets about k8s information when available. This information is best effort only so we try to ignore "expected" errors while still logging errors we wouldn't expect to catch bugs. One of these expected errors is cancellation (e.g., due to a timeout) so we have code to check the status code. However, it appears that if the cancellation came about from a hyper envelope being dropped then the error is emitted asUnknown
fromtonic
. Pretty printed the error looks like:It seems right now there is special code for hyper errors whose source is an
h2::Error
, but the errors in the envelope drop have as a source just a static string so it defaults back to the "unknown" error.Solution
Thankfully
hyper:Error
has ais_canceled
method that checks its innerkind
.My apologies for the lack of test but it appears that
hyper:Error
isn't instantiatable from outside thehyper
crate so there wasn't an easy way to reproduce my specific kind of error in an unit test.