Skip to content

fix(spawn-application, spawn-local-platform): complete onExit() only after output is delivered - #70

Merged
deer merged 1 commit into
mainfrom
process_output_fix
Oct 30, 2026
Merged

deer merged 1 commit into
mainfrom
process_output_fix

Conversation

@deer

@deer deer commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Application.onExit() completed as soon as the underlying Process exited, but the stdout and stderr Pipes deliver output to subscribers asynchronously, so the last lines could still be in flight. A caller that waited on onExit() and then read what its StandardOutputSubscriber or StandardErrorSubscriber had recorded could see missing output or a subscriber that had not yet completed. The same race applied to Customizer.onTerminated, which could run before the output had been delivered. This showed up as intermittent failures in code that launches a short-lived command and parses its output, and it reproduces readily under CPU load.

AbstractApplication now collects the futures returned by opening the stdout and stderr Pipes and, once the Process has exited, waits for all of them before notifying the Customizers. onExit() is built on that combined future, so it completes only after the output has been delivered to subscribers and the customizers have been notified of the termination. The stdin Pipe is intentionally not awaited, since it never ends on its own. When there is no Terminal, there are no Pipes and behavior is unchanged.

One behavior change to be aware of: because the customizer notification is now part of the future that onExit() depends on, an exception thrown from Customizer.onTerminated now fails onExit() instead of being silently dropped in an unobserved future.

MachineComplianceTests gains coverage for stdout and stderr being fully delivered and completed by the time onExit() completes, for output being delivered before customizers are notified of termination, for onExit() completing while a descendant process is still running, and for onExit() failing when a customizer throws. To check the fix against the real symptom, a downstream test that parses the output of git was repeated 300 times under heavy CPU load: it failed 33 times against 0.4.3 and never failed against this change.

@deer
deer merged commit f20481f into main Oct 30, 2026
1 check passed
@deer
deer deleted the process_output_fix branch October 30, 2026 11:02
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