Skip to content

Fix zombie host after BEAM exit on single-instance packs - #19

Merged
dominicletz merged 4 commits into
masterfrom
fix/zombie-host-clean-quit-respawn
Nov 11, 2026
Merged

dominicletz merged 4 commits into
masterfrom
fix/zombie-host-clean-quit-respawn

Conversation

@dominicletz

@dominicletz dominicletz commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Clean system.prepare_quit / host quit now terminates the host so the single-instance lock is released.
  • Unexpected BEAM exits still respawn; add liveness polling and instance.activate immediate respawn when the child is dead.
  • Cover runtime kill, prepare_quit host exit, and activate-respawn in E2E.

Test plan

  • mix test test/e2e/restart_test.exs test/e2e/instance_test.exs --include e2e on Windows (10 passed)
  • macOS/Linux host builds still compile

Note

Medium Risk
Touches core process-lifetime and single-instance locking across all native hosts; incorrect quit vs crash classification could cause unwanted respawns or failed relaunches.

Overview
Fixes zombie single-instance hosts after BEAM dies or quits: clean shutdown now exits the native host so the lock is released, while crash/restart behavior stays on the unexpected-exit path.

On macOS, Linux, and Windows HostController, system.prepare_quit opens a ~3s clean-exit window (no permanent “do not respawn”). If BEAM exits during that window or the host is quitting, the host terminates instead of respawning. A periodic liveness check runs the same exit handler when OS child-watch notifications are missed. instance.activate (and Windows control-pipe handling) can cancel backoff and spawn BEAM immediately when the child is dead but restart_beam is on; Windows replies on the pipe before activate and uses PostMessage so second launches do not deadlock.

Specs bump to v0.2.0 with new YAML cases; E2E covers runtime BEAM kill → respawn, prepare_quit → host exit, and activate → respawn, plus BeamFixture stay_up / kill_direct_children! helpers.

Reviewed by Cursor Bugbot for commit 40437c7. Configure here.

Clean prepare_quit now exits the host, unexpected exits respawn (with liveness and activate safety nets), so a dead BEAM cannot keep the single-instance lock forever.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 3 potential issues.

Fix All in Cursor

Bugbot Autofix is ON, but it could not run because on-demand usage is turned off. To enable Bugbot Autofix, turn on on-demand usage and set a spend limit in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 40437c7. Configure here.

Comment thread native/windows/src/host_controller.cpp Resolved
Comment thread test/support/beam_fixture.ex Resolved
dominicletz and others added 3 commits November 11, 2026 18:52
Guard Win/Linux/macOS exit handlers against a replacement child, and kill children with pgrep -P so macOS e2e can exercise the host.

Co-authored-by: Cursor <cursoragent@cursor.com>
Clear suppressTerminate before NSApp.terminate, and treat Linux zombie children as dead so respawn/activate can reclaim them.

Co-authored-by: Cursor <cursoragent@cursor.com>
Arm quit on prepare_quit, exit(0) on macOS clean BEAM death, keep liveness watching after arming, and detect host death via OS pid.

Co-authored-by: Cursor <cursoragent@cursor.com>
@dominicletz
dominicletz merged commit 04d6514 into master Nov 11, 2026
4 checks passed
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.

1 participant