A StreamTask which is about to finish and thus transitioning its containing Task into the ExecutionState.FINISHED state, can be failed by a concurrent asynchronous checkpointing operation. The problem is that upon termination the StreamTask cancels all concurrent operations (amongst others ongoing asynchronous checkpoints). The cancellation of the async checkpoint triggers the StreamTask#handleAsyncException call which will fail the containing Task. If the handleAsyncException completes before the StreamTask has been properly terminated, then the containing Task will transition into ExecutionState.FAILED instead of ExecutionState.FINISHED.
In order to resolve this race condition, we should check in the StreamTask#handleAsyncException whether the StreamTask is still running or has already been terminated. Only in the former case, we should fail the containing Task.