mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(lifecycle): run afterReset on every Resettable when a beforeReset throws (#4024)
performReset stops every managed container first, then walks the Resettable list and adds each service to `prepared` right before calling its beforeReset(). When one beforeReset() threw, the loop stopped and every later service was never added, so the finally block skipped their afterReset(). Their teardown had already run, though: the SageMaker training runner and endpoint manager had shut their worker pools down and EcsService had stopped its reconciler, and those are only restored in afterReset() (#3937). After such a reset every CreateTrainingJob, CreateEndpoint and UpdateEndpoint returned 500 with RejectedExecutionException and ECS services were never reconciled again until the process restarted. The finally block now runs afterReset() over the full service list in reverse order, dropping the `prepared` list. afterReset() already had to tolerate a reset that failed before clear(); tolerating one that failed before beforeReset() is the same contract, and the Resettable Javadoc now says so. A controller test registers a Resettable whose beforeReset() throws between two others and asserts that the error is rethrown, the wipe and clear() are skipped, and afterReset() still runs on all three, including the one whose beforeReset() never ran. Closes #3952 Closes #3796
This commit is contained in:
1 parent
4c64f2e397
commit
173854cdeb
3 files changed
+36
-4
No files matched your search
@@ -17,6 +17,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
@@ -120,4 +121,31 @@ class EmulatorInfoControllerTest {
|
||||
verify(resettable).afterReset();
|
||||
verify(resettable, never()).clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should call afterReset on every service, even those after a beforeReset that failed, then rethrow")
|
||||
void reset_runsAfterResetOnEveryServiceWhenABeforeResetFails() {
|
||||
Resettable failing = mock(Resettable.class);
|
||||
Resettable later = mock(Resettable.class);
|
||||
doThrow(new IllegalStateException("drain timed out")).when(failing).beforeReset();
|
||||
when(containerTeardowns.iterator()).thenReturn(List.of(sageMakerTeardown).iterator());
|
||||
when(resettables.iterator()).thenReturn(List.of(resettable, failing, later).iterator());
|
||||
|
||||
IllegalStateException thrown = assertThrows(IllegalStateException.class, controller::reset);
|
||||
|
||||
assertEquals("drain timed out", thrown.getMessage());
|
||||
// The teardown already shut down the pools that afterReset() restores, so the service
|
||||
// whose beforeReset() never ran needs afterReset() just as much as the ones that ran.
|
||||
InOrder order = inOrder(sageMakerTeardown, resettable, failing, later);
|
||||
order.verify(sageMakerTeardown).stopManagedContainers();
|
||||
order.verify(resettable).beforeReset();
|
||||
order.verify(failing).beforeReset();
|
||||
order.verify(later).afterReset();
|
||||
order.verify(failing).afterReset();
|
||||
order.verify(resettable).afterReset();
|
||||
verify(later, never()).beforeReset();
|
||||
verify(storageFactory, never()).clearAll();
|
||||
verify(resettable, never()).clear();
|
||||
verify(later, never()).clear();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user