fix(dev): stop orphaning the antfly child on dev-loop shutdown and EADDRINUSE#460
Open
markhayden wants to merge 1 commit into
Open
fix(dev): stop orphaning the antfly child on dev-loop shutdown and EADDRINUSE#460markhayden wants to merge 1 commit into
markhayden wants to merge 1 commit into
Conversation
…DDRINUSE (#459) Two dev-loop defects that minted orphaned antfly processes across generations (diagnosed live; full writeup in #459): - scripts/dev.ts registered SIGINT/SIGTERM handlers before server.ts loads and called process.exit(0) — Node runs signal listeners in registration order, so the lifecycle's async shutdown (the only thing that stops the antfly child) never executed. The dev handler now defers once the lifecycle owns shutdown (globalThis flag set by registerShutdownHandlers; checked without importing lifecycle so an early Ctrl-C during the build phase doesn't load the server module graph). - server.ts had no 'error' listener on listen(): EADDRINUSE threw as an uncaught exception AFTER the full boot (antfly spawned, watcher running), bypassing cleanup. It now logs the port + lsof remediation, routes through the lifecycle shutdown via self-SIGTERM, and exits 1 — the lifecycle's final exit honors a pre-set process.exitCode instead of stamping 0 over it. Verified end-to-end with two isolated-BAKIN_HOME servers on one port: second exits 1 with the named remediation and "Shutdown complete"; first keeps serving and exits cleanly on SIGTERM. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #459.
Two dev-loop defects that minted orphaned antfly processes across
bun run devgenerations (full diagnosis in the issue):scripts/dev.tssignal handlers preempted the lifecycle shutdown. They're registered beforeserver.tsloads and calledprocess.exit(0)— signal listeners run in registration order, sosrc/core/lifecycle.ts's async shutdown (the only path that stops the antfly child) never executed. The dev handler now defers once the lifecycle owns shutdown, via aglobalThisflag set byregisterShutdownHandlers()— deliberately checked without importing lifecycle, so an early Ctrl-C during the build phase doesn't drag in the server module graph.Unhandled
EADDRINUSEcrashed after full boot, skipping cleanup.server.listen()had no'error'listener; a squatted 3737 threw an uncaught exception after antfly was spawned and the watcher started. Now: clear error naming the port +lsofremediation, then self-SIGTERM through the lifecycle shutdown, exiting 1 (lifecycle's finalprocess.exithonors a pre-setprocess.exitCode).Verified end-to-end (isolated
BAKIN_HOME, two servers on one port): second server exits 1 with the named remediation andShutdown complete; first keeps serving and exits cleanly on SIGTERM.Related but intentionally NOT here (they live on the migration branch / PR #457, since that's where the adapter and the
~/.bakin/antflydir are owned):process.on('exit')net in the adapter that kills the antfly child on any JS-level exitSuite: 4658 pass / 0 fail; typecheck + lint clean.
🤖 Generated with Claude Code