Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/cli/src/__tests__/runtime-host-service-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@ describe('managed Runtime Host service', () => {
let startingPid: number | null = null;
let stops = 0;
let observedStartingFence = false;
let publishPidlessSuccessor = false;
const backend: RuntimeHostServiceBackend = {
...createReadyBackend(),
status: async () => ({
Expand Down Expand Up @@ -930,6 +931,10 @@ describe('managed Runtime Host service', () => {
allow: boolean,
) => {
assert.equal(expectedPid, 42);
if (publishPidlessSuccessor) {
serviceState = 'starting';
startingPid = null;
}
return allow
? ({ kind: 'prepared', hostEpoch: 'host-1', pid: 42 } as const)
: ({ kind: 'active_tasks' } as const);
Expand Down Expand Up @@ -1018,6 +1023,26 @@ describe('managed Runtime Host service', () => {
pid: 42,
});
assert.equal(serviceState, 'stopped');

serviceState = 'running';
publishPidlessSuccessor = true;
const stopsBeforeSuccessor = stops;
await assert.rejects(
manageRuntimeHostService(
{
...common,
action: 'retire',
expectedTarget,
allowInterruptActiveTasks: true,
},
backend,
deps,
),
(error: unknown) =>
error instanceof RuntimeHostServiceManagerError && error.code === 'retirement_failed',
);
assert.equal(stops, stopsBeforeSuccessor);
assert.equal(serviceState, 'starting');
});

it('fails closed without stopping a successor that won the State Root', async (t) => {
Expand Down
5 changes: 4 additions & 1 deletion packages/cli/src/runtime-host-service-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,10 @@ async function acquirePreparedRuntimeHostRootRetirementFence(
while (Date.now() < deadline) {
const owner = await tryAcquireInteractiveRootOwner(root);
const status = await backend.status();
if (status.pid !== null && status.pid !== expectedPid) {
if (
status.pid !== expectedPid &&
!(status.pid === null && !status.active && status.state === 'stopped')
) {
await owner?.close().catch(() => undefined);
throw new RuntimeHostServiceManagerError(
'retirement_failed',
Expand Down