Skip to content

Commit

Permalink
parallelise cleanup to minimise chance of hanging
Browse files Browse the repository at this point in the history
previously, sequential cleanups fail to fully cleanup if earlier steps in the sequence fail
  • Loading branch information
RamIdeas committed Oct 25, 2023
1 parent 1521bf3 commit 1084bcb
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions packages/wrangler/src/dev/start-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,11 @@ export async function startDevServer(

return {
stop: async () => {
stop();
await stopWorkerRegistry();
await devEnv.teardown();
await Promise.allSettled([
stop(),
stopWorkerRegistry(),
devEnv.teardown(),
]);
},
// TODO: inspectorUrl,
};
Expand Down Expand Up @@ -246,9 +248,11 @@ export async function startDevServer(
});
return {
stop: async () => {
stop();
await stopWorkerRegistry();
await devEnv.teardown();
await Promise.allSettled([
stop(),
stopWorkerRegistry(),
devEnv.teardown(),
]);
},
// TODO: inspectorUrl,
};
Expand Down Expand Up @@ -372,7 +376,7 @@ async function runEsbuild({
}

export async function startLocalServer(props: LocalProps) {
if (!props.bundle || !props.format) return Promise.resolve({ stop() {} });
if (!props.bundle || !props.format) return { async stop() {} };

// Log warnings for experimental dev-registry-dependent options
if (props.bindings.services && props.bindings.services.length > 0) {
Expand All @@ -392,7 +396,7 @@ export async function startLocalServer(props: LocalProps) {
logger.log(chalk.dim("⎔ Starting local server..."));

const config = await localPropsToConfigBundle(props);
return new Promise<{ stop: () => void }>((resolve, reject) => {
return new Promise<{ stop: () => Promise<void> }>((resolve, reject) => {
const server = new MiniflareServer();
server.addEventListener("reloaded", async (event) => {
await maybeRegisterLocalWorker(event, props.name);
Expand Down Expand Up @@ -420,12 +424,12 @@ export async function startLocalServer(props: LocalProps) {
props.onReady?.(event.url.hostname, parseInt(event.url.port), proxyData);
// Note `unstable_dev` doesn't do anything with the inspector URL yet
resolve({
stop: () => {
stop: async () => {
abortController.abort();
logger.log("⎔ Shutting down local server...");
// Initialization errors are also thrown asynchronously by dispose().
// The `addEventListener("error")` above should've caught them though.
server.onDispose().catch(() => {});
await server.onDispose().catch(() => {});
removeMiniflareServerExitListener();
},
});
Expand Down

0 comments on commit 1084bcb

Please sign in to comment.