Repository navigation
fix(spawn-application, spawn-local-platform): complete onExit() only after output is delivered - #70
Merged
Merged
Conversation
…after output is delivered
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Application.onExit()completed as soon as the underlyingProcessexited, but the stdout and stderrPipes deliver output to subscribers asynchronously, so the last lines could still be in flight. A caller that waited ononExit()and then read what itsStandardOutputSubscriberorStandardErrorSubscriberhad recorded could see missing output or a subscriber that had not yet completed. The same race applied toCustomizer.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.AbstractApplicationnow collects the futures returned by opening the stdout and stderrPipes and, once theProcesshas exited, waits for all of them before notifying theCustomizers.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 stdinPipeis intentionally not awaited, since it never ends on its own. When there is noTerminal, there are noPipes 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 fromCustomizer.onTerminatednow failsonExit()instead of being silently dropped in an unobserved future.MachineComplianceTestsgains coverage for stdout and stderr being fully delivered and completed by the timeonExit()completes, for output being delivered before customizers are notified of termination, foronExit()completing while a descendant process is still running, and foronExit()failing when a customizer throws. To check the fix against the real symptom, a downstream test that parses the output ofgitwas repeated 300 times under heavy CPU load: it failed 33 times against0.4.3and never failed against this change.