Skip to content

Commit 8221c53

Browse files
committed
Further fixes
1 parent 56d63c9 commit 8221c53

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

packages/playground/cli/src/run-cli.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -550,10 +550,10 @@ export async function runCLI(args: RunCLIArgs): Promise<RunCLIServer | void> {
550550
let loadBalancer: LoadBalancer;
551551
let playground: RemoteAPI<PlaygroundCliWorker>;
552552

553-
const playgroundsToCleanUp: {
554-
playground: RemoteAPI<PlaygroundCliWorker>;
555-
worker: Worker;
556-
}[] = [];
553+
const playgroundsToCleanUp: Map<
554+
Worker,
555+
RemoteAPI<PlaygroundCliWorker>
556+
> = new Map();
557557

558558
/**
559559
* Expand auto-mounts to include the necessary mounts and steps
@@ -883,10 +883,12 @@ export async function runCLI(args: RunCLIArgs): Promise<RunCLIServer | void> {
883883

884884
disposing = true;
885885
await Promise.all(
886-
playgroundsToCleanUp.map(async ({ playground, worker }) => {
887-
await playground.dispose();
888-
await worker.terminate();
889-
})
886+
[...playgroundsToCleanUp].map(
887+
async ([worker, playground]) => {
888+
await playground.dispose();
889+
await worker.terminate();
890+
}
891+
)
890892
);
891893
if (server) {
892894
await new Promise((resolve) => server.close(resolve));
@@ -937,11 +939,10 @@ export async function runCLI(args: RunCLIArgs): Promise<RunCLIServer | void> {
937939
fileLockManagerPort,
938940
nativeInternalDirPath
939941
);
940-
941-
playgroundsToCleanUp.push({
942-
playground: initialPlayground,
943-
worker: initialWorker.worker,
944-
});
942+
playgroundsToCleanUp.set(
943+
initialWorker.worker,
944+
initialPlayground
945+
);
945946

946947
await initialPlayground.isReady();
947948
wordPressReady = true;
@@ -981,16 +982,16 @@ export async function runCLI(args: RunCLIArgs): Promise<RunCLIServer | void> {
981982
// be configured differently than post-boot workers.
982983
// For example, we do not enable Xdebug by default for the initial worker.
983984
await loadBalancer.removeWorker(initialPlayground);
984-
// TODO: Wrap in a cleanup function and reuse for all worker cleanup.
985985
await initialPlayground.dispose();
986986
await initialWorker.worker.terminate();
987+
playgroundsToCleanUp.delete(initialWorker.worker);
987988
}
988989

989990
logger.log(`Preparing workers...`);
990991

991992
// Boot additional workers using the handler
992993
const initialWorkerProcessIdSpace = processIdSpaceLength;
993-
// Just take the first Playground instance to be relayed to others.
994+
// Just take the first Playground instance to be returned to the caller.
994995
[playground] = await Promise.all(
995996
workers.map(async (worker, index) => {
996997
const firstProcessId =
@@ -1009,11 +1010,10 @@ export async function runCLI(args: RunCLIArgs): Promise<RunCLIServer | void> {
10091010
nativeInternalDirPath,
10101011
});
10111012

1012-
playgroundsToCleanUp.push({
1013-
playground: additionalPlayground,
1014-
worker: worker.worker,
1015-
});
1016-
1013+
playgroundsToCleanUp.set(
1014+
worker.worker,
1015+
additionalPlayground
1016+
);
10171017
loadBalancer.addWorker(additionalPlayground);
10181018

10191019
return additionalPlayground;
@@ -1048,6 +1048,7 @@ export async function runCLI(args: RunCLIArgs): Promise<RunCLIServer | void> {
10481048
if (await playground?.fileExists(errorLogPath)) {
10491049
phpLogs = await playground.readFileAsText(errorLogPath);
10501050
}
1051+
await disposeCLI();
10511052
throw new Error(phpLogs, { cause: error });
10521053
}
10531054
},

0 commit comments

Comments
 (0)