Skip to main content

Module sweep

Module sweep 

Source
Expand description

Stopping what bynk dev’s wranglers leave behind (#1742).

bynk dev stops each wrangler dev by signalling the child it spawned. That child is rarely the server. Resolved via npx, it is npx, and the server is four processes further down (sh -c wrangler → wrangler’s node launcher → its CLI → two workerd serves); a signal to npx reaches none of them. Resolved on PATH, the child is the launcher, which does pass SIGTERM on. But when a context’s wrangler crashes, its workerds are re-parented to init before bynk dev ever acts, and nothing walks from a child to them any more. Either way the survivors keep their ports, and the next bynk dev fails at boot with bind(): Address already in use.

Two properties of those survivors outlast the re-parenting:

  • Process group. Nothing in the chain leaves the group it was spawned into, which is bynk dev’s own: they share it so a Ctrl-C reaches them all.
  • Working directory. bynk dev starts each wrangler inside its worker dir under the managed build dir, and every descendant inherits it.

sweep stops the processes that have both, so it reaches orphans without guessing by name. The working directory is what keeps it from touching an unrelated process: when bynk dev is not a group leader (a script without job control runs it), its group can hold the script’s other jobs. Neither bynk dev itself nor its ancestors are ever selected.

Unix only. Windows has neither process groups nor a working directory to read. There, bynk dev puts each wrangler in a job object instead, which holds the whole tree, orphans included, and stops it as one (#1762).

Functions§

stragglers
The processes sweep would stop now.
sweep
Stop every process in this process group whose working directory is under root: SIGTERM first, then SIGKILL for what is still running after grace. Returns once none is left, or after SIGKILL has been given a moment to land.