Skip to content

NodeBridge dispose should cancel in-flight init to avoid orphaned processes #63

@bbopen

Description

@bbopen

Summary

Disposing a NodeBridge while init() is in flight can leave a Python subprocess running because dispose() returns early when child is still unset, but startProcess() later assigns this.child.

Failure mode

  • Trigger bridge.init() (or bridge.call() which calls init()), then call dispose() before startProcess() assigns this.child.
  • dispose() sees child as undefined, exits without killing anything.
  • startProcess() completes and leaves a live Python subprocess despite disposed=true.

Evidence

  • src/runtime/node.ts in init() and startProcess().

Proposed fix

  • Add a disposal guard inside startProcess() after spawn: if this.disposed, kill the child immediately and bail.
  • Optionally track a cancel token/promise so dispose() can await startProcess() and kill the child deterministically.

Acceptance criteria

  • Disposing during init leaves no running Python subprocess.
  • Subsequent calls after dispose fail with BridgeDisposedError and do not leak processes.
  • Add a regression test that triggers dispose mid-init.

Metadata

Metadata

Assignees

Labels

area:runtime-nodeArea: Node runtime bridgebugSomething isn't workingpriority:p2Priority P2 (medium)

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions