Skip to content

Commit f8c52b9

Browse files
authored
fix: allow wrangler pages dev sessions to be reloaded (#4054)
#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. :(
1 parent 0d4a4ca commit f8c52b9

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

.changeset/tricky-poems-type.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
fix: allow `wrangler pages dev` sessions to be reloaded
6+
7+
Previously, `wrangler pages dev` attempted to send messages on a closed IPC
8+
channel when sources changed, resulting in an `ERR_IPC_CHANNEL_CLOSED` error.
9+
This change ensures the channel stays open until the user exits `wrangler pages dev`.

packages/wrangler/src/pages/dev.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -637,14 +637,13 @@ export const Handler = async ({
637637

638638
CLEANUP_CALLBACKS.push(stop);
639639

640-
void waitUntilExit().then(() => {
641-
CLEANUP();
642-
process.exit(0);
643-
});
644-
645640
process.on("exit", CLEANUP);
646641
process.on("SIGINT", CLEANUP);
647642
process.on("SIGTERM", CLEANUP);
643+
644+
await waitUntilExit();
645+
CLEANUP();
646+
process.exit(0);
648647
};
649648

650649
function isWindows() {

0 commit comments

Comments
 (0)