Skip to content

Commit 768c511

Browse files
lcclaude
andcommitted
fix(network-proxy): let proxied connections die with their request
The proxy agents were built with keepAlive, which retains an idle connection after each request. The client's default handler is NodeHttp2Handler with disableConcurrentStreams: true, so before this handler existed every request got an isolated HTTP/2 session that was destroyed on stream close, and nothing outlived it. IEmbedder has no disposal contract to reclaim a pooled connection, so drop the option rather than add a cleanup path with no call site. This also matches src/api/providers/bedrock.ts, which passes no agent options. Co-Authored-By: Claude Opus 5 <[email protected]>
1 parent 4eae3b3 commit 768c511

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

‎src/utils/__tests__/networkProxy.spec.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,13 +528,14 @@ describe("networkProxy", () => {
528528
expect(NodeHttpHandler).not.toHaveBeenCalled()
529529
})
530530

531-
it("should build both proxy agents with a reusable tunnel", () => {
531+
it("should build both proxy agents without keeping connections alive", () => {
532532
process.env.HTTPS_PROXY = "http://proxy.corp:3128"
533533

534534
expect(createProxyRoutingRequestHandler()).toBeDefined()
535535

536-
expect(HttpProxyAgent).toHaveBeenCalledWith("http://proxy.corp:3128", { keepAlive: true })
537-
expect(HttpsProxyAgent).toHaveBeenCalledWith("http://proxy.corp:3128", { keepAlive: true })
536+
// No agent options: an idle connection would outlive the request that opened it.
537+
expect(HttpProxyAgent).toHaveBeenCalledWith("http://proxy.corp:3128")
538+
expect(HttpsProxyAgent).toHaveBeenCalledWith("http://proxy.corp:3128")
538539
const { proxied } = innerHandlers()
539540
expect(proxied?.options?.httpAgent).toBe(vi.mocked(HttpProxyAgent).mock.instances[0])
540541
expect(proxied?.options?.httpsAgent).toBe(vi.mocked(HttpsProxyAgent).mock.instances[0])

‎src/utils/networkProxy.ts‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -445,20 +445,18 @@ export interface ProxyRoutingHandler {
445445
* override — so the destination is only known once a request has been built. Choosing here is
446446
* what makes NO_PROXY apply to the host actually called, rather than one guessed up front.
447447
*
448-
* Both routes are HTTP/1.1. A client whose default handler is NodeHttp2Handler therefore drops
449-
* to 1.1 once a proxy is configured, including on the direct route; the Bedrock calls involved
450-
* are unary requests, and the chat provider already tunnels over 1.1.
448+
* The agents take no options, so no connection outlives its request. Both routes are HTTP/1.1:
449+
* a client defaulting to NodeHttp2Handler drops to 1.1 once a proxy is configured, which is what
450+
* the chat provider already does.
451451
*/
452452
class ProxyRoutingRequestHandler implements ProxyRoutingHandler {
453453
private readonly direct = new NodeHttpHandler()
454454
private readonly proxied: NodeHttpHandler
455455

456456
constructor(proxyUrl: string) {
457-
// Callers such as the code-index embedder send one request per item, so keep the tunnel.
458-
const agentOptions = { keepAlive: true }
459457
this.proxied = new NodeHttpHandler({
460-
httpAgent: new HttpProxyAgent(proxyUrl, agentOptions),
461-
httpsAgent: new HttpsProxyAgent(proxyUrl, agentOptions),
458+
httpAgent: new HttpProxyAgent(proxyUrl),
459+
httpsAgent: new HttpsProxyAgent(proxyUrl),
462460
})
463461
}
464462

0 commit comments

Comments
 (0)