Skip to content

fix: kill ttyd process on early exit from Evaluate#737

Open
tomenden wants to merge 1 commit intocharmbracelet:mainfrom
tomenden:fix/cleanup-ttyd-on-early-exit
Open

fix: kill ttyd process on early exit from Evaluate#737
tomenden wants to merge 1 commit intocharmbracelet:mainfrom
tomenden:fix/cleanup-ttyd-on-early-exit

Conversation

@tomenden
Copy link
Copy Markdown

@tomenden tomenden commented Mar 31, 2026

Fixes #738

Summary

ttyd processes are left running after VHS exits when Evaluate() returns early (before Record()/teardown() are reached).

The deferred cleanup at evaluator.go:45 only calls v.close(), which is set to vhs.browser.Close — it never kills the ttyd process. The terminate() method that properly kills both browser and ttyd is only called via teardown(), which is only reachable after Record() starts.

Affected code paths (all between Start() and Record()):

  • Page.Wait fails (line 50-53)
  • A SET command fails (line 59-63)
  • Video dimensions too small (line 78-91)
  • A Hide block command fails (line 106-109)

Additionally, Start() itself didn't clean up ttyd if browser launch or page creation failed after ttyd was already started.

Fix

  • evaluator.go: The deferred cleanup now also kills the ttyd process, so every early-return path is covered.
  • vhs.go: Start() now kills ttyd if subsequent browser/page setup fails, preventing orphaned processes even on initialization errors.

Test plan

  • go build ./... passes
  • Run vhs with a tape that triggers an early exit (e.g., invalid SET command), then verify no orphaned ttyd processes remain (ps aux | grep ttyd)
  • Run vhs normally and verify recordings still work correctly

The deferred cleanup in Evaluate() only called v.close(), which closes
the browser but not the ttyd process. Any early return between Start()
and the teardown() call (e.g. SET command failure, dimension check,
Hide block error) would leave an orphaned ttyd process running.

Also clean up ttyd in Start() if browser launch or page creation fails.
@tomenden tomenden requested a review from a team as a code owner March 31, 2026 13:26
@tomenden tomenden requested review from aymanbagabas and meowgorithm and removed request for a team March 31, 2026 13:26
@tomenden
Copy link
Copy Markdown
Author

Fixes #738

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.

ttyd process leaked on early exit from Evaluate

1 participant