-
-
Notifications
You must be signed in to change notification settings - Fork 639
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
Actions not executed for cancelled futures #2010
Comments
Note that while this doesn't affect the bug itself, |
Thanks for the info. I guess |
It seems that the problem code is FutureImpl.java#L199. Computation fails in I believe we should use classic |
And maybe |
see #1963 |
I think the @Override
public boolean cancel(boolean mayInterruptIfRunning) {
synchronized (lock) {
if (isCompleted()) {
return false;
} else {
return Try.of(() -> job == null || job.cancel(mayInterruptIfRunning)).onSuccess(cancelled -> {
if (cancelled) {
complete(Try.failure(new CancellationException()));
}
}).getOrElse(false);
}
}
} Interestingly we already have a unit test: @SuppressWarnings("InfiniteLoopStatement")
@Test
public void shouldInterruptLockedFuture() {
final Future<?> future = Future.of(() -> {
while (true) {
Try.run(() -> Thread.sleep(100));
}
});
future.onComplete(r -> fail("future should lock forever"));
future.cancel();
assertCancelled(future);
} After the fix is applied, the onComplete handler, which throws an AssertionError, is executed. Currently the onComplete actions are executed on different threads (which will be changed with #1530), so the unit test is still green. |
According to the documentation, actions registered with
onFailure
should be executed when a future is cancelled. However, this does not seem to be the case as the following code prints nothing:The text was updated successfully, but these errors were encountered: