diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/StopDatafeedAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/StopDatafeedAction.java index 9e5c1f47883..eb985f7418e 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/StopDatafeedAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/StopDatafeedAction.java @@ -366,20 +366,29 @@ public class StopDatafeedAction ActionListener listener) { DatafeedState taskStatus = DatafeedState.STOPPING; datafeedTaskTask.updatePersistentStatus(taskStatus, ActionListener.wrap(task -> { - // we need to fork because we are now on a network threadpool - threadPool.executor(MachineLearning.UTILITY_THREAD_POOL_NAME).execute(new AbstractRunnable() { - @Override - public void onFailure(Exception e) { - listener.onFailure(e); - } + // we need to fork because we are now on a network threadpool + threadPool.executor(MachineLearning.UTILITY_THREAD_POOL_NAME).execute(new AbstractRunnable() { + @Override + public void onFailure(Exception e) { + listener.onFailure(e); + } - @Override - protected void doRun() throws Exception { - datafeedTaskTask.stop("stop_datafeed (api)", request.getStopTimeout()); - listener.onResponse(new Response(true)); + @Override + protected void doRun() throws Exception { + datafeedTaskTask.stop("stop_datafeed (api)", request.getStopTimeout()); + listener.onResponse(new Response(true)); + } + }); + }, + e -> { + if (e instanceof ResourceNotFoundException) { + // the task has disappeared so must have stopped + listener.onResponse(new Response(true)); + } else { + listener.onFailure(e); + } } - }); - }, listener::onFailure)); + )); } private void sendResponseOrFailure(String datafeedId, ActionListener listener, diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsIT.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsIT.java index 79dd934d732..fe55243b1b5 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsIT.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsIT.java @@ -110,7 +110,6 @@ public class DatafeedJobsIT extends MlNativeAutodetectIntegTestCase { }); } - @AwaitsFix(bugUrl="https://github.com/elastic/x-pack-elasticsearch/issues/1536") public void testRealtime_multipleStopCalls() throws Exception { String jobId = "realtime-job-multiple-stop"; final String datafeedId = jobId + "-datafeed";