Skip to content

cli 0.8.1: fall back across addresses until TLS completes - #33

Merged
qiansc merged 1 commit into
mainfrom
fix/cli-tls-fallback
Dec 2, 2026
Merged

qiansc merged 1 commit into
mainfrom
fix/cli-tls-fallback

Conversation

@qiansc

@qiansc qiansc commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Background

On some networks a site's address accepts the TCP connection but never completes the TLS handshake, while the site's addresses of the other family work. Node's fetch keeps the first address that connects and waits for TLS until UND_ERR_CONNECT_TIMEOUT. IPv4/IPv6 fallback (autoSelectFamily, added in 0.8.0) only covers TCP failures, so the only workaround was --dns-result-order=ipv6first. doctor checked TCP only, so it reported such addresses as reachable.

Changes

  • cli/src/transport.ts: HTTPS requests use an address only after its TLS handshake has completed. Certificate and host name are verified as usual.
    • If an address has not finished within a second, the next address is tried in parallel, alternating IPv4 and IPv6, and the first one to finish is used.
    • The family that worked is remembered per host in the configuration file for 7 days.
    • When every address fails, the error lists each address and its reason, for example TLS_HANDSHAKE_TIMEOUT, and the request counts as unsent.
  • When Node's fetch is told to use the environment proxy (NODE_USE_ENV_PROXY=1 or --use-env-proxy), requests keep going through fetch.
  • doctor now completes a TLS handshake with each address. When one family connects without TLS, it advises --dns-result-order=ipv6first (or ipv4first) for MCP clients.
  • Skill and CLI README updated (generated from the templates); CLI and plugin version 0.8.1.

Risks

  • The request layer changes from fetch to node:https. Redirects are still not followed, matching the previous redirect: manual. Certificate checks are unchanged.
  • The config file gains a routes field; older CLIs ignore it.

Backward compatibility

  • Commands, flags and output are unchanged; there are no server changes. Release: merge, then gh release create v0.8.1.

Testing

  • bun test: 22 pass. New src/transport.test.ts runs the bundled client under real Node, with 127.0.0.1 accepting TCP but never speaking TLS and ::1 serving HTTPS. It covers:
    • The first request succeeds in under 1.5 s and IPv6 is remembered; the second request goes straight to IPv6.
    • A certificate whose name does not match is rejected.
    • When no address completes TLS, the request is reported unsent and switches to the other entry.
    • Address ordering and the proxy decision.
  • doctor on https://context4ai.org/sourcegraph shows TCP and TLS per address.
  • tsc: no new errors; sync-deployment --check passes.

🤖 Generated with Claude Code

…cks TLS per address

An address that accepts TCP but never completes TLS made every request wait
for UND_ERR_CONNECT_TIMEOUT: Node's fetch keeps the first address that
connects, so IPv4/IPv6 fallback does not help. Requests now use an address only
once its TLS handshake has completed (certificate and host name verified),
start the next address after a second, alternating families, and remember the
family that worked per host. NODE_USE_ENV_PROXY keeps Node's fetch so the
proxy is used. doctor also completes a TLS handshake with each address.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@qiansc
qiansc merged commit 5fd62f6 into main Dec 2, 2026
5 checks passed
@qiansc
qiansc deleted the fix/cli-tls-fallback branch December 2, 2026 16:14
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