Skip to content

Commit 5bb796f

Browse files
[ML] No error when datafeed stops during updating to started (#46495)
Investigating the test failure reported in #45518 it appears that the datafeed task was not found during a tast state update. There are only two places where such an update is performed: when we set the state to `started` and when we set it to `stopping`. We handle `ResourceNotFoundException` in the latter but not in the former. Thus the test reveals a rare race condition where the datafeed gets requested to stop before we managed to update its state to `started`. I could not reproduce this scenario but it would be my best guess. This commit catches `ResourceNotFoundException` while updating the state to `started` and lets the task terminate smoothly. Closes #45518
1 parent f00836d commit 5bb796f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed/DatafeedManager.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.apache.logging.log4j.LogManager;
99
import org.apache.logging.log4j.Logger;
1010
import org.elasticsearch.ElasticsearchStatusException;
11+
import org.elasticsearch.ResourceNotFoundException;
1112
import org.elasticsearch.action.ActionListener;
1213
import org.elasticsearch.client.Client;
1314
import org.elasticsearch.cluster.ClusterChangedEvent;
@@ -95,7 +96,12 @@ public void onResponse(PersistentTask<?> persistentTask) {
9596

9697
@Override
9798
public void onFailure(Exception e) {
98-
finishHandler.accept(e);
99+
if (e instanceof ResourceNotFoundException) {
100+
// The task was stopped in the meantime, no need to do anything
101+
logger.info("[{}] Aborting as datafeed has been stopped", datafeedId);
102+
} else {
103+
finishHandler.accept(e);
104+
}
99105
}
100106
});
101107
}, finishHandler::accept

0 commit comments

Comments
 (0)