-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(client): add SendRequest::try_send_request()
method
#3691
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
Merged
Conversation
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
67f019b
to
6624bc6
Compare
This method returns a `TrySendError` type, which allows for returning the request back to the caller if an error occured between queuing and trying to write the request. This method is added for both `http1` and `http2`.
6624bc6
to
37067a0
Compare
bartlomieju
added a commit
to denoland/deno
that referenced
this pull request
Jul 2, 2024
Reland of #24056 that doesn't suffer from the problem that was discovered in #24261. It uses upgraded `hyper` and `hyper-util` that fixed the previous problem in hyperium/hyper#3691.
sbmsr
pushed a commit
to sbmsr/deno-1
that referenced
this pull request
Jul 2, 2024
Reland of denoland#24056 that doesn't suffer from the problem that was discovered in denoland#24261. It uses upgraded `hyper` and `hyper-util` that fixed the previous problem in hyperium/hyper#3691.
zebreus
pushed a commit
to zebreus/deno
that referenced
this pull request
Jul 8, 2024
Reland of denoland#24056 that doesn't suffer from the problem that was discovered in denoland#24261. It uses upgraded `hyper` and `hyper-util` that fixed the previous problem in hyperium/hyper#3691.
cratelyn
added a commit
to cratelyn/hyper
that referenced
this pull request
May 5, 2025
this commit introduces a new trait implementation for `hyper::client::conn::TrySendError<T>`. this commit allows a `TrySendError<T>` to be constructed `From` a conventional `hyper::Error`. one example of a motivating use case for this change is that this is needed in order to use interfaces like `hyper::client::conn::http2::SendRequest::try_send_request()` or `hyper::client::conn::http1::SendRequest::try_send_request()` in the context of tower middleware; the `Service<T>` trait's signature is such that the same error type be returned from `Service::poll_ready()` and `Service::call()`. thus, the `?` operator may construct a `TrySendError<T>` from errors possibly returned by `hyper::client::conn::http2::SendRequest::poll_ready()` or `hyper::client::conn::http1::SendRequest::poll_ready()`, within a `Service<T>` that eventually calls `try_send_request()` in the context of `Service::call()`. --- see: * hyperium#3691 * https://docs.rs/hyper/latest/hyper/client/conn/struct.TrySendError.html * https://docs.rs/hyper/latest/hyper/struct.Error.html * https://docs.rs/hyper/latest/hyper/client/conn/http2/struct.SendRequest.html#method.try_send_request * https://docs.rs/tower/latest/tower/trait.Service.html#associatedtype.Error * https://docs.rs/hyper/latest/hyper/client/conn/http1/struct.SendRequest.html#method.poll_ready * https://docs.rs/hyper/latest/hyper/client/conn/http2/struct.SendRequest.html#method.poll_ready Signed-off-by: katelyn martin <[email protected]>
cratelyn
added a commit
to cratelyn/hyper
that referenced
this pull request
May 6, 2025
this commit introduces a new trait implementation for `hyper::client::conn::TrySendError<T>`. this commit allows a `TrySendError<T>` to be constructed `From` a conventional `hyper::Error`. one example of a motivating use case for this change is that this is needed in order to use interfaces like `hyper::client::conn::http2::SendRequest::try_send_request()` or `hyper::client::conn::http1::SendRequest::try_send_request()` in the context of tower middleware; the `Service<T>` trait's signature is such that the same error type be returned from `Service::poll_ready()` and `Service::call()`. thus, the `?` operator may construct a `TrySendError<T>` from errors possibly returned by `hyper::client::conn::http2::SendRequest::poll_ready()` or `hyper::client::conn::http1::SendRequest::poll_ready()`, within a `Service<T>` that eventually calls `try_send_request()` in the context of `Service::call()`. --- see: * hyperium#3691 * https://docs.rs/hyper/latest/hyper/client/conn/struct.TrySendError.html * https://docs.rs/hyper/latest/hyper/struct.Error.html * https://docs.rs/hyper/latest/hyper/client/conn/http2/struct.SendRequest.html#method.try_send_request * https://docs.rs/tower/latest/tower/trait.Service.html#associatedtype.Error * https://docs.rs/hyper/latest/hyper/client/conn/http1/struct.SendRequest.html#method.poll_ready * https://docs.rs/hyper/latest/hyper/client/conn/http2/struct.SendRequest.html#method.poll_ready Signed-off-by: katelyn martin <[email protected]>
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.
This change adds a
try_send_request()
method toSendRequest
. This method returns aTrySendError
type, which allows for returning the request back to the caller if an error occured between queuing and trying to write the request.This method is added for both
http1
andhttp2
.Closes #3673
Closes seanmonstar/reqwest#2325
(Well, after hyper-util makes use of it.)
Problem
If you try to
send_request(req)
at the same time the server is closing the connection, it's possible hyper will notice the HUP before the request gets serialized. If so, theoretically the request is safe to try on another connection.But there isn't a mechanism for hyper to give the request back. And since the pool was moved out of hyper, it doesn't know how to just grab another connection.
Need: a mechanism to return the request on specific kinds of errors.
Options
try_send_request(req)
, which returns aTrySendError
.hyper::Error
.req.extensions()
.TrySendError
Pros:
std::sync::mpsc::TrySendError
as prior art.Cons:
http1::SendRequest
andhttp2::SendRequest
.send_request()
have handled this?fn send()
and hidetry_send_request()
andsend_request()
.Embed in
hyper::Error
After writing all this out, this is probably not possible.
Pros:
Cons:
Error::request()
set of APIs seems to pollute the type.ext
API can access it...Error
around but didn't expect theRequest<B>
to live with it?ext
be set to signal to hyper that it's OK? Then it becomes opt-in.Request<B>
if the body is!Send
ext
passed converts into anAny
...Pass
ext::CaptureTrySend
?Pros:
B
Error
for longer than expectedCons:
req.extensions()
for basically every request...