futures-rs icon indicating copy to clipboard operation
futures-rs copied to clipboard

Change the output of `RemoteHandle<T>` to `Option<T>` for checking `Remote` cancellation reliably

Open EFanZh opened this issue 3 years ago • 0 comments

Currently, std::panic::resume_unwind is called if I await a RemoteHandle with a canceled Remote future:

https://github.com/rust-lang/futures-rs/blob/96c2fc4668f8bfb428352e8a1558972961bd31a1/futures-util/src/future/future/remote_handle.rs#L65-L66

But https://doc.rust-lang.org/std/panic/fn.resume_unwind.html#notes says that

panics in Rust are not always implemented via unwinding, but they may be implemented by aborting the process

which means cancelling a Remote future might terminate the process immediately and there is no way to avoid it. This might be a little dangerous. Here are my suggestions:

  1. Warn user that awaiting a RemoteHandle whose Remote future is canceled before ready will panic the awaiting thread, maybe also suggest user to use OneShot channel manually for reliable cancellation checking.
  2. Change the output type of RemoteHandle<T> to Option<T> or Result<T, Canceled>. This will break many existing programs due to API change, but maybe change it on the next major version?

EFanZh avatar Nov 10 '21 10:11 EFanZh