fix(sagemaker): restore the worker pools in afterReset, not clear() (#3937)

* fix(sagemaker): restore the worker pools in afterReset, not clear()

A state reset runs every container teardown, and the SageMaker training
runner and endpoint manager shut their worker pools down there. Since
#3797 they create a new pool in clear(), but the reset controller skips
clear() as soon as the storage wipe or an earlier service's clear()
throws, so one failed reset still left both pools terminated and every
later CreateTrainingJob, CreateEndpoint and UpdateEndpoint returned 500
with RejectedExecutionException until Floci restarted.

Both beans now recreate the pool in afterReset(), which the controller
runs from a finally block for every service it prepared, whether or not
the wipe or a clear() succeeded. Shutdown still never runs it, so the
pools stay down there. clear() keeps only its stopRequested wipe, and
the ContainerTeardown Javadoc names afterReset() as the hook to use.

Refs #3796

* fix(ecs): restart the reconciler in afterReset, not clear()

EcsService restarted the reconciler its reset teardown had stopped in
clear(), the same one-way path the SageMaker pools had: a reset whose
storage wipe or earlier clear() threw skipped it and left ECS without a
reconciler until the emulator restarted. The restart now lives in
afterReset(), which the reset controller runs for every prepared service
regardless of that failure, matching the rule the ContainerTeardown
Javadoc states and what the SageMaker beans now do.

Refs #3796
This commit is contained in:
Matheus André authored and GitHub committed 2026-09-19 18:30:57 -04:00
1 parent bc018afad0
commit 52941e90ef
7 files changed
+64 -34

No files matched your search

@@ -78,7 +78,7 @@ class EcsServiceTeardownTest {
}
@Test
void clearRestartsTheReconcilerThatAResetTeardownStopped() {
void afterResetRestartsTheReconcilerThatAResetTeardownStopped() {
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
when(config.services().ecs().mock()).thenReturn(false); // docker mode
when(config.effectiveBaseUrl()).thenReturn("http://localhost:4566");
@@ -91,13 +91,15 @@ class EcsServiceTeardownTest {
null);
service.initializeStorage();
// A reset runs the teardown and then clear(); shutdown runs only the teardown.
// A reset runs the teardown, then clear(), and afterReset() last, even when the wipe or
// a clear() threw; shutdown runs only the teardown. afterReset() alone must bring the
// reconciler back.
service.stopManagedContainers();
assertTrue(service.isReconcilerShutdown());
service.clear();
service.afterReset();
assertFalse(service.isReconcilerShutdown());
service.clear();
service.afterReset();
assertFalse(service.isReconcilerShutdown());
service.stopManagedContainers();
@@ -18,22 +18,24 @@ import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
/**
* A state reset runs the container teardown, which shuts the worker pool down, and then
* {@code clear()}. Shutdown runs only the teardown.
* A state reset runs the container teardown, which shuts the worker pool down, then
* {@code clear()}, and {@code afterReset()} last, even when the wipe or a {@code clear()}
* failed. Shutdown runs only the teardown.
*/
class SageMakerEndpointManagerTest {
@Test
void teardownStopsThePoolAndClearRestoresIt() {
void teardownStopsThePoolAndAfterResetRestoresIt() {
SageMakerEndpointManager manager = manager();
assertTrue(manager.acceptsWork());
manager.stopManagedContainers();
assertFalse(manager.acceptsWork());
manager.clear();
// A reset whose wipe threw skips clear(); afterReset() alone must bring the pool back.
manager.afterReset();
assertTrue(manager.acceptsWork());
manager.clear();
manager.afterReset();
assertTrue(manager.acceptsWork());
manager.stopManagedContainers();
@@ -44,6 +46,7 @@ class SageMakerEndpointManagerTest {
SageMakerEndpointManager manager = manager();
manager.stopManagedContainers();
manager.clear();
manager.afterReset();
SageMakerService service = mock(SageMakerService.class);
CountDownLatch published = new CountDownLatch(1);
@@ -21,22 +21,24 @@ import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
/**
* A state reset runs the container teardown, which shuts the worker pool down, and then
* {@code clear()}. Shutdown runs only the teardown.
* A state reset runs the container teardown, which shuts the worker pool down, then
* {@code clear()}, and {@code afterReset()} last, even when the wipe or a {@code clear()}
* failed. Shutdown runs only the teardown.
*/
class SageMakerTrainingRunnerTest {
@Test
void teardownStopsThePoolAndClearRestoresIt() {
void teardownStopsThePoolAndAfterResetRestoresIt() {
SageMakerTrainingRunner runner = runner();
assertTrue(runner.acceptsWork());
runner.stopManagedContainers();
assertFalse(runner.acceptsWork());
runner.clear();
// A reset whose wipe threw skips clear(); afterReset() alone must bring the pool back.
runner.afterReset();
assertTrue(runner.acceptsWork());
runner.clear();
runner.afterReset();
assertTrue(runner.acceptsWork());
runner.stopManagedContainers();
@@ -47,6 +49,7 @@ class SageMakerTrainingRunnerTest {
SageMakerTrainingRunner runner = runner();
runner.stopManagedContainers();
runner.clear();
runner.afterReset();
SageMakerService service = mock(SageMakerService.class);
CountDownLatch reported = new CountDownLatch(1);