Skip to content

Fix Windows unix socket URL round-trip - #6416

Merged
samuv merged 3 commits into
stacklok:mainfrom
stantheman0128:fix/6291-windows-afunix-url
Aug 25, 2026
Merged

Fix Windows unix socket URL round-trip#6416
samuv merged 3 commits into
stacklok:mainfrom
stantheman0128:fix/6291-windows-afunix-url

Conversation

@stantheman0128

Copy link
Copy Markdown
Contributor

Summary

I reproduced this on Windows 11 with go test ./pkg/api ./pkg/server/discovery. Drive-letter emit was already unix:///C:%5C.... What still failed:

  • ListenURL for /tmp/test.sock came out as unix:////tmp/test.sock (extra slash).
  • ParseUnixSocketPath("unix:///var/run/thv.sock") ran the path through filepath.Clean, so Windows turned it into \var\run\thv.sock and rejected it as not absolute.
  • Health tests built "unix://"+socketPath, which url.Parse rejects on a drive letter (invalid port).

I put emit on one helper (discovery.UnixSocketURL) and taught the parser the two absolute forms instead of three one-off patches.

  • POSIX paths keep three slashes. Drive-letter paths still get the synthetic leading slash that net/url needs.
  • POSIX unix:/// stays slash-form on Windows. The old four-slash alias still parses.
  • Health tests call the helper.

Fixes #6291

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests (task test)
  • E2E tests (task test-e2e)
  • Linting (task lint-fix)
  • Manual testing (describe below)

Win11, go1.26.5, worktree at origin/main e25de16. I did not run full task test (whole-repo -race). Focused:

go test -timeout 90s -count=1 ./pkg/server/discovery/
ok  	github.com/stacklok/toolhive/pkg/server/discovery	1.511s

go test -timeout 90s -count=1 ./pkg/api/ -run "TestListenURL|TestSocketURL"
ok  	github.com/stacklok/toolhive/pkg/api	4.847s

go test -timeout 60s -count=1 ./pkg/api/ -run "TestSetupUnixSocket|TestCleanupUnixSocket|TestCreateListener|TestIsNamedPipe"
ok  	github.com/stacklok/toolhive/pkg/api	1.817s

TestListenURL/Unix_socket_returns_unix_URL, TestUnixSocketURL, POSIX/drive-letter round-trip, and TestParseUnixSocketPath_FourSlashAlias are in that set.

API Compatibility

  • This PR does not break the v1beta1 API, OR the api-break-allowed label is applied and the migration guidance is described above.

Changes

File Change
pkg/server/discovery/unix_url.go Shared UnixSocketURL plus POSIX vs drive-letter parse
pkg/server/discovery/health.go ParseUnixSocketPath delegates to that parse
pkg/api/socket_windows.go / socket_unix.go socketURL calls UnixSocketURL (npipe branch unchanged)
*_test.go Round-trip, four-slash alias, health tests stop concatenating

Does this introduce a user-facing change?

Yes, for AF_UNIX discovery URLs. A POSIX socket path on Windows is now unix:///tmp/... (three slashes), not unix:////tmp/.... Drive-letter URLs are unchanged (unix:///C:%5C...). Named pipes are unchanged.

Special notes for reviewers

I left pkg/container/docker/sdk/client_unix.go (unix://+docker socket into moby WithHost) alone. That is a different host string, unix-only build.

I used Cursor to write the patch after reproducing the failures on this box.

Claimed and assigned on #6291.

ListenURL prepended a slash onto POSIX paths and emitted unix:////tmp/.... Health tests concatenated unix:// onto drive-letter paths, which url.Parse rejects as an invalid port. One helper now emits both forms. The parser keeps POSIX paths in slash form on Windows and still accepts the old four-slash alias.

Signed-off-by: stantheman0128 <stanshih888@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@codecov

codecov Bot commented Aug 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 77.72%. Comparing base (e25de16) to head (213eefa).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
pkg/server/discovery/unix_url.go 96.42% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6416      +/-   ##
==========================================
+ Coverage   77.70%   77.72%   +0.01%     
==========================================
  Files         756      760       +4     
  Lines       72788    72907     +119     
==========================================
+ Hits        56563    56669     +106     
- Misses      16220    16233      +13     
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…r .. paths.

Signed-off-by: stantheman0128 <stanshih888@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

@samuv samuv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the focused fix and the coverage for both POSIX and drive-letter round trips. I found one path-validation edge case where a drive-relative Windows path is accepted as absolute, so I left an inline comment. The current PR checks are green.

Checklist:

  • Tests: New regression tests cover the intended paths, and CI is green.
  • Docs: No additional docs needed for this internal compatibility fix.
  • Registry impact: None.
  • Security: One path-validation issue noted inline.
  • Backwards compatibility: The legacy four-slash alias remains supported.

Comment thread pkg/server/discovery/unix_url.go Outdated
Signed-off-by: Po-Han Shih <stanshih888@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@samuv
samuv merged commit b30ca2b into stacklok:main Aug 25, 2026
48 checks passed
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.

Windows: AF_UNIX unix:// URLs fail to parse and round-trip

2 participants