Skip to content

Commit

Permalink
fix: prevent zombie workerd processes (#4635)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbbot committed Dec 20, 2023
1 parent 35e8a5d commit 5bc2699
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .changeset/metal-houses-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"wrangler": patch
---

fix: prevent zombie `workerd` processes

Previously, running `wrangler dev` would leave behind "zombie" `workerd` processes. These processes prevented the same port being bound if `wrangler dev` was restarted and sometimes consumed lots of CPU time. This change ensures all `workerd` processes are killed when `wrangler dev` is shutdown.

To clean-up existing zombie processes, run `pkill -KILL workerd` on macOS/Linux or `taskkill /f /im workerd.exe` on Windows.
6 changes: 5 additions & 1 deletion packages/wrangler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -765,13 +765,17 @@ export async function main(argv: string[]): Promise<void> {
}
throw e;
} finally {
await closeSentry();
// In the bootstrapper script `bin/wrangler.js`, we open an IPC channel, so
// IPC messages from this process are propagated through the bootstrapper.
// Make sure this channel is closed once it's no longer needed, so we can
// cleanly exit. Note, we don't want to disconnect if this file was imported
// in Jest, as that would stop communication with the test runner.
if (typeof jest === "undefined") process.disconnect?.();

// Close Sentry after disconnecting the IPC channel. Doing this before leads
// to hanging `workerd` processes.
// TODO(soon): work out why
await closeSentry();
}
}

Expand Down

0 comments on commit 5bc2699

Please sign in to comment.