Replies: 1 comment
-
I expect that if you drop a future from the Rust SDK, it will bubble down to Hyper and cancel the request, but I have admittedly not personally verified that. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently, I know of 2 ways of how to "cancel" a future:
Just stop polling it and eventually drop it.
This is the easiest one, if you never poll a future again it won't make progress. This is how https://docs.rs/tokio/latest/tokio/time/fn.timeout.html works for example. If the timeout expires the underlying future is just dropped.
The downside of that approach is that the future might not expect being dropped. Assume that the future is stopped in the middle of reading a huge chunk of data from a socket. The next code that tries to read data from the same socket will receive the remaining parts of the data, which is most likely just garbage to that code.
Tokio calls this "cancellation safety". It also allows to use the future safely in
tokio::select!
. For example intokio::io::AsyncWriteExt
,write
is cancellation safe whilewrite_all
is not.Using explicit cancellation using
CancellationToken
. There are several crates providing this functionality. For exampletokio_util::sync::CancellationToken
(docs). Basically this is explicit cancellation where the future needs to explicitly poll the cancellation state. The advantage is that the future can control at which points it can be cancelled and at which points it cannot. It also allows cleanup work after cancellation.Unfortunately, It doesn't seem like the AWS SDK support either of those options. Is there anything I am missing or is there no way to cancel a request?
Beta Was this translation helpful? Give feedback.
All reactions