Open awx-michael-wang opened 5 months ago
Yes this is a bug, looks like we ignore the promise if it has completed regardless of how it completed
We should check if it has completed exceptionally or not.
Fixing this though could break backwards compatibility since this could effect workflow code. Any fix will need to make sure to preserve history compatibility with workflows that have this scenario.
In the mean time the easiest way to workaround this bug I think is to implement a wrapper around promiseAllOf
to check if any promise passed in failed
static Promise<Void> allOf(Promise<?>... promises) {
for (Promise<?> p : promises) {
if (p.isCompleted() && p.getFailure() != null) {
return Workflow.newFailedPromise(p.getFailure());
}
}
return WorkflowInternal.promiseAllOf(promises);
}
}
Thank you. I did implement a similar wrapper:
fun <T> List<Promise<T>>.safeAllOf(): Promise<Void> {
val existFailure = this.filter { it.isCompleted }
.firstNotNullOfOrNull { it.failure }
return if (existFailure != null) {
Workflow.newFailedPromise(existFailure)
} else {
Promise.allOf(this)
}
}
Expected Behavior
Promise.allOf(promises)
should fail as long as one of thepromises
fails, no matter it is already failed before calling theallOf
or after.Actual Behavior
If one
Promise
inpromises
is already failed before callingallOf
, the failure is ignored.How to reproduce
A workflow like following will ended successfully.
Analysis
AllOfPromise#addPromise
only handles the promise that is not completed.Specifications