RequestFuture#get blocks forever if an in-flight request is cancelled
- Dominant language
- Java
- Stars
- 3.4k
- Forks
- 751
- Avg merge
- 8h 49m
- Merged PRs (30d)
- 2
Description
RequestFuture#get waits for either onResponse or onErrorResponse to be called before attempting to return a result. However, if a request is cancelled, by design, neither callback will be executed. This means get() will block forever (or until the user-specified timeout, if one is given).
Proposal to fix:
- Add an optional CancelListener that can be set on a request
- Have cancel() only set mCanceled = true when called from the main thread, and queue a runnable to do so otherwise
- Call the cancel listener when setting mCanceled = true (on the main thread)
- Have RequestFuture implement CancelListener and set itself as the listener in setRequest, and call notify() in the listener.
- Ensure we use setRequest everywhere we use RequestFuture so it is cancellable
Contributor guide
Assessment
This issue has not been assessed yet.