Skip to content

fix: centralize ttdy host#749

Open
oliverxchen wants to merge 1 commit into
charmbracelet:mainfrom
oliverxchen:fix-localhost-open
Open

fix: centralize ttdy host#749
oliverxchen wants to merge 1 commit into
charmbracelet:mainfrom
oliverxchen:fix-localhost-open

Conversation

@oliverxchen
Copy link
Copy Markdown

@oliverxchen oliverxchen commented May 11, 2026

  • ttyd binds to 127.0.0.1 but vhs.go was opening Chrome at http://localhost:. This does not fail on all machines, but may fail when Chrome chooses IPv6 first.

  • This fix centralizes the ttdy host in ttyHost, uses it for both the ttyd --interface and the browser URL, and adds vhs_test.go to ensure they stay aligned.

  • I have read CONTRIBUTING.md.

  • Bug fix, not applicable. I have created a discussion that was approved by a maintainer (for new features).

How to check whether your machine is susceptible to the bug

Start ttyd the same way VHS does, bound to IPv4 loopback only:

ttyd --port=19760 --interface 127.0.0.1 --once --writable "$SHELL"

In another terminal, test IPv4 and IPv6 localhost separately:

curl -4 -I http://localhost:19760
curl -6 -I http://localhost:19760
curl -g -I 'http://[::1]:19760'

A machine is likely affected when IPv4 works but IPv6 fails:

curl -4 -I http://localhost:19760
# HTTP/1.1 200 OK

curl -6 -I http://localhost:19760
# curl: (7) Failed to connect to localhost port 19760

curl -g -I 'http://[::1]:19760'
# curl: (7) Failed to connect to ::1 port 19760

This can combine badly if localhost resolves to ::1 before 127.0.0.1:

dscacheutil -q host -a name localhost

If ::1 appears before 127.0.0.1, Chrome may try IPv6 first when VHS opens http://localhost:<port>, while ttyd is only listening on 127.0.0.1.

- ttyd binds to 127.0.0.1 but vhs.go was opening Chrome at
  http://localhost:<port>. This fails when Chrome choose IPv6 first.
- This fix centralizes the ttdy host in `ttyHost`, uses it for both the
  ttyd --interface and the browser URL, and adds `vhs_test.go` to ensure
  they stay aligned.
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