Repository navigation
fix(plugins): tie plugin host lifetime to the parent and bound IPC diagnostics - #2381
Conversation
…agnostics Plugin host processes could outlive their parent: nothing exited the host when the parent IPC channel went away, so a plugin holding a referenced timer kept the process alive forever. Diagnostics also went through the same transport unguarded, so a failing send inside the exception handlers could re-enter them recursively. - Exit on lost ownership: node transports exit on `disconnect`; Electron utilityProcess's pinned parent-port never surfaces one, so the host keeps a ping/pong round-trip (`PI_PLUGIN_PING_INTERVAL_MS` / `PI_PLUGIN_PING_MISSES`, 10s / 2 by default) and exits when the parent stops answering. The broker replies to `ping` with `pong`. A failed send marks the transport broken and exits; nothing re-enters it. - Guard diagnostics: `log`/reply sends are best-effort (`trySend`) and the `uncaughtException` / `unhandledRejection` handlers swallow reporting failures instead of escaping or recursing. Ordinary exception reporting, plugin responsiveness, and concurrent host API calls are unchanged while the parent is healthy. Fixes vastsa#2374
vastsa
left a comment
There was a problem hiding this comment.
Independent production-process regression on e875d4f reproduces an incomplete fix: asynchronous Node IPC send failures still recursively log. The fixture overrides process.send so a log send queues process.emit("error", EPIPE), matching the asynchronous error boundary. Both uncaught-exception and unhandled-rejection cases repeatedly attempt log sends and hit the fixture recursion guard (exit 77). trySend only catches synchronous throws; send provides no callback and no transport error handler marks transportBroken before the error reaches uncaughtException. Please handle asynchronous send errors with a callback/transport error listener and one idempotent terminal path, and add both async regression cases. The two new lifetime tests both disconnect the channel and do not exercise this failure. This is a reproduced root-cause gap, so I am leaving this unmerged. The older fixture expects exit 1 whereas this PR chooses exit 0; synchronous exit-code differences are not counted as defects. Native Electron parent-kill acceptance has not been run in this review; please also supply that evidence, including a healthy-parent responsiveness check.
Node IPC delivery is asynchronous: when the parent connector dies between the send and the flush, `process.send` reports the failure through a callback or a process-level `error` event (EPIPE), not a synchronous throw. The previous try/catch-only guard never saw those, so diagnostics sent from inside uncaughtException/unhandledRejection kept re-entering the handlers recursively (reviewer-reproduced, exit 77). - trySend/call pass a delivery callback; a failed async delivery joins a single idempotent terminal path (transportBroken + one process.exit) - a process-level `error` handler catches async channel failures before they become uncaughtException; Electron's parent-port `close` and `messageerror` take the same path - two regression tests: fixture send that emits EPIPE asynchronously under an uncaughtException and an unhandledRejection, asserting one clean exit and exactly one broken-channel note - new parent-kill acceptance script for the Electron utilityProcess keepalive, including a healthy-parent ping responsiveness check
…lure The child-side node IPC channel invokes the process.send callback with null on a successful flush. The async delivery-failure path treated any callback invocation as a transport error and rejected the pending call, so every host->parent call during plugin load (e.g. commands.register) failed with null and plugin load broke (PLUGIN_LOAD_FAILED in e2e-plugin-projects). Only a non-null error is now a delivery failure; the idempotent terminal-exit path is unchanged.
|
Independent recheck: async exception/rejection delivery failures now terminate rather than reaching the prior recursion guard (the old diagnostic's exit-1 assertions are intentionally not acceptance requirements). Native macOS Electron 43.6.0 parent-kill acceptance PASS: healthy parent answered 5 pings, orphan exited ~201 ms after SIGKILL. Lifetime + bus + command ownership + isolation: 28/28 PASS. Incorporated actual origin/main 3cc8b4a non-destructively, no conflicts, preserved author commits; pushed a6675c2 with maintainer permission. Repeated all 28 tests and native acceptance on that integrated candidate: PASS; diff check clean. Waiting for refreshed CI and actual merge-tree verification before approval/merge. Minor optional harness cleanup: fail() references brokerOutput before initialization if Electron is absent; not a product root-cause blocker. |
vastsa
left a comment
There was a problem hiding this comment.
Final landing check: all five current-head CI checks now pass, including the previously pending Rust test job. Latest main remains 3cc8b4a; fetched actual merge candidate and independently validated head share tree ed3753cb21921e15c5d200fa919da3d552ebd304. Prior recorded 28/28 production regressions and native macOS Electron healthy-parent/SIGKILL acceptance apply unchanged to this exact candidate; no redundant rerun claimed. Async delivery failures converge on the guarded terminal path and the reproduced recursive diagnostics/orphan lifecycle defects are resolved. Approved for merge.
Summary
Plugin host processes could outlive their parent and recursively log IPC errors (issue #2374):
disconnect; ElectronutilityProcess's pinned parent-port closes its connector without emitting a JSdisconnect, so the host keeps a ping/pong round-trip (PI_PLUGIN_PING_INTERVAL_MS/PI_PLUGIN_PING_MISSES, default 10s x 2) and exits when the parent stops answering. The broker replies topingwithpong. A failed send also marks the transport broken and exits — the host never lingers without its owner.logand res replies now go through a best-efforttrySend; a failing send never throws into the caller, and theuncaughtException/unhandledRejectionhandlers swallow reporting failures instead of escaping or re-entering recursively. Ordinary exception reporting and plugin responsiveness while the parent is healthy are unchanged.Test
apps/desktop/test/plugin-host-lifetime.test.mjs: host exits cleanly (code 0) on parent disconnect despite a referenced plugin timer (the issue's repro); host exits when the send channel fails. Both fail onmainand pass with the fix.plugin-bus,plugin-command-ownership,plugin-isolation,main-module-path,plugin-agent-extensions,plugin-audio-unsupported,plugin-clipboard-history,plugin-complete,plugin-composer-transform,plugin-provider-oauth: all pass.tsc -p apps/desktop --noEmit: clean. Biome: these paths are repo-ignored.Fixes #2374
Review follow-up
Async send failures (review ①/②).
trySendpreviously only caught synchronous throws; a dead connector reports delivery failure asynchronously — via theprocess.sendcallback or a process-levelerrorevent (EPIPE) — so diagnostics sent from insideuncaughtException/unhandledRejectionre-entered those handlers recursively (thanks for the fixture; we reproduced the exit-77 loop the same way). The transport now handles delivery at every surface:sendpasses a delivery callback on the node IPC channel (trySendand the host-APIcallpath both use it); Electron's parent-port getsclose/messageerrorlisteners.errorhandler catches async channel failures before they can surface asuncaughtException.transportBrokenis set once, one stderr note is emitted, andprocess.exit(0)runs exactly once (guarded by anexitStartedflag) — later failure events see the flag and stop.Async regression tests (review ③). Two new cases in
test/plugin-host-lifetime.test.mjs, one drivinguncaughtException, oneunhandledRejection. The fixture plugin overridesprocess.sendso diagnosticlogframes succeed synchronously but reportEPIPEasynchronously viaprocess.emit("error", ...)(the real Node IPC error boundary), while other frames still reach the real channel. Each test asserts the host exits by itself with code 0 (not SIGKILLed by the harness timeout) and that exactly one "parent IPC channel is broken" note is written — no recursion. Both tests fail (host loops until the 5s harness SIGKILL) against the previous commit and pass with the fix. Full file:node --test test/plugin-host-lifetime.test.mjs→ 4 pass.Electron parent-kill acceptance (review ④). New
apps/desktop/test/plugin-host-parent-kill-acceptance.mjs, runnable withnode test/plugin-host-parent-kill-acceptance.mjsfromapps/desktop(needs theelectrondevDependency;ELECTRON_BINoverrides the binary). It forks the real host under an ElectronutilityProcesswith a minimal broker: phase 1 proves healthy-parent responsiveness (everypinganswered withpong, round-trips keep flowing past the miss budget, host stays alive, last pong within deadline); phase 2 SIGKILLs the Electron main — no disconnect handshake — and asserts the orphaned host exits by itself within the keepalive budget (observed ~200 ms with a 1 s interval / 2 misses). Negative control: againstmain(no keepalive) phase 1 times out, as expected.Note honestly: this PR was developed in a sandbox without a preinstalled Electron; we installed Electron 43 headless (xvfb) there and both phases passed, but we ask the maintainer to run the acceptance script in their normal environment (macOS/Windows included) as the authoritative check — the sandbox run is Linux-only evidence. The exit-0-on-disconnect expectations in the older tests are unchanged (review ⑤: not treated as a defect).