Skip to content

fix(cli): stop what the app started before an oxnode watch restart - #879

Merged
Brooooooklyn merged 1 commit into
mainfrom
fix/watch-restart-kill-descendants
Oct 22, 2026
Merged

Brooooooklyn merged 1 commit into
mainfrom
fix/watch-restart-kill-descendants

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Member

Closes #875

Problem

On a restart, oxnode watch sent --kill-signal to the app only, and started the next run as soon as the app exited. A server the app started in a normal subprocess kept its port, so the next run got EADDRINUSE.

before:  oxnode ──SIGTERM──▶ app ✗        server (now under PID 1) still holds :port
                                           next run ──▶ EADDRINUSE
after:   oxnode ──SIGTERM──▶ app ✗
                 ──SIGTERM──▶ server ✗     (once the app exits)
                 wait until gone ──▶ next run

Fix

  • Before the signal, the kill effect lists the app's descendants (subtree(processTable(), pid)). Once the app exits they move to PID 1 and can't be found by parent any more.
  • When the app exits, the ones still running get the same signal once. oxnode then checks every 25 → 250 ms and dispatches childExit when they are gone. The reducer is unchanged.
  • The kill timeout keeps running through the wait, so --kill-timeout, Return and a second Ctrl+C force kill what is left (killTree now also takes the known list). After a force kill oxnode waits at most 1 s, then logs the PIDs left and goes on. SIGKILL cannot end a process stuck on a hung mount.
  • Gone means: no row, a zombie (as PID 1 in a container oxnode never reaps them), or another start time (a reused PID). processTable() now reads stat and lstart from ps, falling back to the two columns, and the state and start time from /proc/<pid>/stat.
  • Unchanged: Windows (it already ends the tree with taskkill /T), and stopping for exit, apart from a force kill now waiting for what it killed.

Not covered (README "Limits")

  • A process the app starts while it is stopping, or leaves behind when it exits on its own: it is not in the list.
  • tsx watch and node --watch don't do this either. nodemon waits, but only until the app exits.

Tests

  • watch-cli.spec.ts: the issue's case (a server in a subprocess cleans up, then the next run binds the same port), a server that ignores SIGTERM under --kill-timeout=300, and SIGTERM to oxnode during the wait. All three fail on main.
  • watch-units.spec.ts: /proc state and start time, ps with stat/lstart, stillRunning (reused PID, zombie, late grandchild), and signalAll.
  • vp run test and OXC_TRANSFORM_ALL=true vp run test pass (571), as do lint and fmt.

🤖 Generated with Claude Code

On a restart, oxnode watch sent the kill signal to the app alone and
started the next run as soon as the app exited. A server the app had
started in a subprocess kept running and held its port (#875).

Now the kill effect lists the app's descendants before the signal (once
the app exits they move to PID 1 and cannot be found). When the app
exits, the ones still running get the same signal, and the next run
starts once they are gone. The kill timeout, Return and a second Ctrl+C
force kill them too. Zombies count as gone, and a PID with another start
time is another process. After a force kill oxnode waits at most 1 s.

Closes #875

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T04:02:56.214933Z 2f8f80a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Brooooooklyn
Brooooooklyn merged commit 152e787 into main Oct 22, 2026
67 checks passed
@Brooooooklyn
Brooooooklyn deleted the fix/watch-restart-kill-descendants branch October 22, 2026 04:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

oxnode watch restart leaves processes the app started running, so a port stays busy

1 participant