Skip to content

fix(tauri): detect and respawn a dead Marlin subprocess; kill on drop - #175

Merged
CameronBrooks11 merged 1 commit into
mainfrom
fix/marlin-subprocess-recovery
Jun 25, 2026
Merged

CameronBrooks11 merged 1 commit into
mainfrom
fix/marlin-subprocess-recovery

Conversation

@CameronBrooks11

Copy link
Copy Markdown
Member

Bug R2 from the latent-bug audit (subprocess lifecycle; merges T2 + T4).

Problem

  • acquire_io gated spawning on guard.is_none(). Once a MarlinSubprocess was stored it was handed back forever — even after the helper process had exited — so every stdin write failed with a broken pipe and the integration never recovered without an app restart.
  • MarlinSubprocess held the Child as _child with no Drop, so the interactive Python process was never killed — on app close/reload it lingered as an orphan holding the serial port open, blocking the next session.

Fix

  • Add child_has_exited() (non-blocking try_wait()); acquire_io resets the state to None when the current subprocess is dead, so the next command respawns a fresh one.
  • Add impl Drop for MarlinSubprocess to kill() + wait() the child, so it's reaped on shutdown and when a dead instance is replaced (no orphan / port leak).

Test (runs in CI via the new cargo-test step)

child_has_exited_true_for_finished_process (spawns true, waits, asserts dead) and child_has_exited_false_for_running_process (spawns sleep 30, asserts alive). The acquire_io wiring and Drop are verified by inspection (constructing a real MarlinSubprocess needs the bundled CLI).

Couldn't run cargo test locally (tauri GTK deps); CI runs it — see checks.

acquire_io used guard.is_none(), so once a MarlinSubprocess was stored it
was reused forever even after the helper process had exited — every stdin
write then failed with a broken pipe and it never recovered without an app
restart. Detect an exited child via try_wait() and reset the state so the
next command respawns. Also add Drop to kill+reap the child so it does not
linger as an orphan holding the serial port after close/reload or replace.
Tests cover the child_has_exited predicate for finished and running processes.
@CameronBrooks11
CameronBrooks11 merged commit 87c1c86 into main Jun 25, 2026
15 checks passed
@CameronBrooks11
CameronBrooks11 deleted the fix/marlin-subprocess-recovery branch June 25, 2026 22:23
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