mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(emr-serverless): end a cancelled run when Docker refuses the stop (#6510)
The Docker runner's stop() sent the driver a docker stop and caught only a 404 or a 304. Any other Docker error escaped the executor task that cancels a run, unlogged, and the run stayed CANCELLING until its driver exited by itself, which a STREAMING run's never does. stop() now only marks the run as stopping. The run's own thread, which looks at the driver every 250 ms, reads the mark at its next look, ends the run and removes the driver, as it does at a timeout, so no Docker error can lose a cancel. The removal is ContainerLifecycleManager's stopAndRemove, which logs what Docker refuses and removes by force. Follow-up to #6469.
This commit is contained in:
1 parent
857d312a45
commit
1ea49d9432
2 files changed
+39
-40
No files matched your search
+19
-10
@@ -1,7 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.emrserverless;
|
||||
|
||||
import com.github.dockerjava.api.DockerClient;
|
||||
import com.github.dockerjava.api.exception.NotModifiedException;
|
||||
import com.github.dockerjava.api.exception.InternalServerErrorException;
|
||||
import com.github.dockerjava.api.model.Container;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerBuilder;
|
||||
@@ -20,6 +20,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@@ -28,7 +29,6 @@ import static org.mockito.ArgumentMatchers.anyMap;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -109,20 +109,29 @@ class EmrServerlessSparkRunnerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void aCancelThatFindsTheDriverAlreadyExitedStillStopsTheRun() {
|
||||
void aCancelEndsTheRunAndRemovesItsDriverEvenWhenDockerWouldRefuseAStop() {
|
||||
EmrServerlessSparkRunner runner = runner();
|
||||
// Docker answers a stop of an exited container with HTTP 304.
|
||||
SparkJobRunner.Job job = job(Duration.ofMillis(50));
|
||||
when(docker.stopContainerCmd("driver").withTimeout(0).exec())
|
||||
.thenThrow(new NotModifiedException("Container already stopped"));
|
||||
SparkJobRunner.Job job = job(Duration.ZERO);
|
||||
doAnswer(started -> {
|
||||
runner.stop(job.jobRunId());
|
||||
return null;
|
||||
}).when(progress).started();
|
||||
.thenThrow(new InternalServerErrorException("daemon busy"));
|
||||
// The driver never exits by itself, as a STREAMING run's; the cancel comes from another task,
|
||||
// whose exceptions go nowhere, while the driver is being watched.
|
||||
AtomicBoolean cancelled = new AtomicBoolean();
|
||||
when(docker.inspectContainerCmd("driver").exec().getState().getRunning()).thenAnswer(look -> {
|
||||
if (cancelled.compareAndSet(false, true)) {
|
||||
try {
|
||||
runner.stop(job.jobRunId());
|
||||
} catch (RuntimeException ignored) {
|
||||
// Dropped, as the executor drops what its task throws; the assertions below catch a lost cancel.
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
SparkJobRunner.Outcome outcome = runner.run(job, progress);
|
||||
|
||||
assertTrue(outcome.stopped());
|
||||
verify(progress, never()).timedOut();
|
||||
verify(lifecycle).stopAndRemove("driver", null, 0);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user