Skip to content

Commit

Permalink
fix: allow wrangler pages dev sessions to be reloaded (#4054)
Browse files Browse the repository at this point in the history
#3951 introduced a change that closed the bootstrapper's IPC channel
when Wrangler exited. Whenever `wrangler (pages) dev` reloads, an
event is sent on this channel to indicate the dev server is ready.
Unfortunately, `wrangler pages dev`'s handler doesn't wait for the
dev session to exit before resolving its returned promise, meaning
the channel is closed as soon as the dev server is ready, not when
Wrangler exits. This means that ready events sent from reloads result
in an `ERR_IPC_CHANNEL_CLOSED` that crashes Wrangler. :(
  • Loading branch information
mrbbot authored Sep 28, 2023
1 parent 0d4a4ca commit f8c52b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 9 additions & 0 deletions .changeset/tricky-poems-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"wrangler": patch
---

fix: allow `wrangler pages dev` sessions to be reloaded

Previously, `wrangler pages dev` attempted to send messages on a closed IPC
channel when sources changed, resulting in an `ERR_IPC_CHANNEL_CLOSED` error.
This change ensures the channel stays open until the user exits `wrangler pages dev`.
9 changes: 4 additions & 5 deletions packages/wrangler/src/pages/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,14 +637,13 @@ export const Handler = async ({

CLEANUP_CALLBACKS.push(stop);

void waitUntilExit().then(() => {
CLEANUP();
process.exit(0);
});

process.on("exit", CLEANUP);
process.on("SIGINT", CLEANUP);
process.on("SIGTERM", CLEANUP);

await waitUntilExit();
CLEANUP();
process.exit(0);
};

function isWindows() {
Expand Down

0 comments on commit f8c52b9

Please sign in to comment.