You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SettableListenableFuture setException is inconsistent with callbacks under race [SPR-15409] #19972
In continuation of #19781 and #19766 I decided to test setException method of SettableListenableFuture and received another portion of strange results.
With methods set(value) and setException(new Exception()) executed under race following cases are possible:
Both methods return false but SuccessCallback is executed
Both methods return false but FailureCallback is executed
I consider these cases as two flavors of the same problem - actually I expect that one of two methods will always return true.
There was indeed a bug in SettableTask.checkCompletingThread: We should only reset the marker after a successful check, otherwise a non-successful check may invalidate it and a subsequent potentially successful check can't find the corresponding marker anymore. I've fixed that in master now and will backport it to 4.3.8.
Note that your test has a race condition of its own: For a valid immediate comparison, each success/successCallback and exception/failCallback pair needs to be checked within a common monitor for the pair, otherwise they may be temporarily out of sync.
synchronized (container.SUCCESS_MONITOR) {
if (container.result.successCallback && !container.result.success) {
System.out.println("SuccessCallback without success!");
}
}
synchronized (container.SUCCESS_MONITOR) {
// success flag and success callback flag set within the same monitor
container.result.success = container.future.set("foo");
}
and the same for the setException case, e.g. with a container.FAIL_MONITOR. Alternatively, I guess you could also batch the results and compare all of them at the very end.
Activity
spring-projects-issues commentedon Apr 7, 2017
Juergen Hoeller commented
There was indeed a bug in
SettableTask.checkCompletingThread: We should only reset the marker after a successful check, otherwise a non-successful check may invalidate it and a subsequent potentially successful check can't find the corresponding marker anymore. I've fixed that in master now and will backport it to 4.3.8.Note that your test has a race condition of its own: For a valid immediate comparison, each
success/successCallbackandexception/failCallbackpair needs to be checked within a common monitor for the pair, otherwise they may be temporarily out of sync.and the same for the
setExceptioncase, e.g. with acontainer.FAIL_MONITOR. Alternatively, I guess you could also batch the results and compare all of them at the very end.spring-projects-issues commentedon Apr 8, 2017
Ivan Sopov commented
I've build current master from sources and all my tests pass - thank you!
Thanks for this catch - indeed Main-based "simple" test reports failures even with the fix and has its own bug.