Repository navigation
Route daemon WebSockets through the environment proxy - #7504
Merged
Merged
Conversation
The daemon starts with --use-env-proxy, which makes Node's global http and https agents honor HTTP_PROXY, HTTPS_PROXY and NO_PROXY. The ws library supplies its own createConnection, so a WebSocket without an explicit agent dials the target directly. On a machine that can reach the internet only through a CONNECT proxy, the server connection and the bb connect tunnel never connect. Pass Node's global agent for the URL scheme to the server WebSocket constructor and the default connect tunnel socket. With no proxy set, or without --use-env-proxy, the global agents connect directly, so behavior is unchanged. Loopback stays direct through the NO_PROXY entries the launcher already adds. Fixes get-bb#4957
2 tasks done
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.
Human comments
What was wrong
The launcher starts the host daemon with
--use-env-proxy(packages/bb-app/src/launcher.ts:2944,:3206), and it adds loopback toNO_PROXY. That flag makes Node's globalhttpandhttpsagents andfetchuseHTTP(S)_PROXY. Butwsalways sets its owncreateConnection, and Node uses the global agent only when the request has nocreateConnection. The daemon opens its server connection (apps/host-daemon/src/websocket-constructor.ts:11-18) and its connect tunnel (apps/host-daemon/src/connect-tunnel/index.ts:154) with noagent. So these sockets connected directly and ignored the proxy. A daemon that can reach the server only through a proxy could not connect (#4957). The docs listed this as a known gap ("including daemon WebSockets").What changed
apps/host-daemon/src/websocket-constructor.ts: newwebSocketAgent(url)returnshttps.globalAgentforwss:andhttps:URLs, andhttp.globalAgentfor other URLs. The constructor now always passesagent, with headers when they are set.apps/host-daemon/src/connect-tunnel/index.ts: the default tunnel socket passesagent: webSocketAgent(url).apps/host-daemon/src/ws.d.ts: addsagent?: Agentto the localwstype definitions.apps/host-daemon/src/websocket-constructor.test.ts(new): starts a local proxy and a local WebSocket server. It runs the real module in a childnode --use-env-proxywithHTTP(S)_PROXYandNO_PROXY=localhost,127.0.0.1,::1. Aws://dial goes through the proxy, with and without headers. Awss://dial sendsCONNECTto the proxy. A loopback dial connects directly. The test is skipped when Node does not support--use-env-proxy, and it needs no network.docs/configuration.md,packages/templates/src/templates/bb-guide-customization.md: the proxy text now includes daemon WebSockets.No wire change and no protocol version bump. No new dependencies.
Limits:
--use-env-proxy, for example on Node 22.19-22.20 where the launcher drops the flag, the global agents do not use the proxy, so behavior is the same as before.ws://server through a proxy needs a proxy that forwards upgrades.wss://usesCONNECT.How you verified
websocket-constructor.ts):AssertionError: expected { proxied: 'error ENOTFOUND', ...(3) } to deeply equal { proxied: 'header=sent', ...(3) }. The proxy saw no request.connect-tunnel.test.ts(10 tests) andserver-connection.test.ts(22 tests) pass.pnpm exec turbo run lint lint:type-aware typecheck test --filter=@bb/host-daemon --filter=@bb/templates: lint and typecheck pass.@bb/templates47 of 47.@bb/host-daemon874 passed and 1 failed:injected-skills.test.tstimed out at 15 s under high machine load. It fails the same way on unchangedmainat 88cf8f644c in the same run and passes alone.@bb/host-daemontypecheck passes, and the three affected test files pass, 33 of 33.Fixes #4957