kill ttyd on early Evaluate exit and on Start failure#752
Open
c-tonneslan wants to merge 1 commit into
Open
Conversation
The deferred cleanup in Evaluate only called vhs.close, which was just vhs.browser.Close. Any early return after Start() succeeded but before Record() got going left ttyd alive. Same story if Start() itself failed after starting ttyd but before the browser was ready: nothing was wired up to kill the orphan. Add a shutdown method that closes the browser and kills ttyd, and is safe to run more than once so the existing terminate path keeps working. Point vhs.close at it once Start completes, and add a one-shot defer inside Start that kills ttyd if we bail out before getting that far. Closes charmbracelet#738. Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
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.
Closes #738.
Evaluatedefersv.close(), which was justvhs.browser.Close. Any early return betweenStart()andRecord()(aPage.Waiterror, a failingSET, dimensions too small, aHideblock failure) left ttyd alive. The same was true ifStart()itself failed aftervhs.tty.Start()but before the browser was usable.This adds a
shutdownmethod that closes the browser and kills ttyd, swallowsos.ErrProcessDoneso it's safe to call afterterminate()has already run, and ignores nil fields so aVHSthat never reachedStart()is fine too.Start()now pointsvhs.closeatshutdownand uses a one-shot defer to clean up ttyd if it returns early. If the browser comes up but the page open fails, the browser is also closed.Verified with the reproducer from the issue (no ttyd left in
ps aux | grep ttyd).Added unit tests for the empty-VHS, kills-tty, and idempotent cases. The TTY-kill tests skip on Windows since they shell out to
sleep.