Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/envd-connection-limit-env-var.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"e2b": patch
---

Expose `E2B_ENVD_CONNECTIONS` environment variable to configure the envd REST file API connection pool limit (default remains 10). Previously the connection count was hardcoded with no runtime override, unlike the RPC transport which already supported `E2B_ENVD_RPC_CONNECTIONS`.
10 changes: 8 additions & 2 deletions packages/js-sdk/src/envd/http2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ export function createEnvdFetch(proxy?: string): typeof fetch {
return cached
}

// Keep one origin connection for short envd REST calls. If ALPN falls back
// to h1, this favors connection pressure over per-sandbox throughput.
const envdFetch = createEnvdFetchForRuntime(runtime, {
connectionLimit: getEnvdConnectionLimit(),
inflightLimit: getEnvdInflightLimit(),
proxy,
})
Expand All @@ -119,6 +118,13 @@ export function createEnvdRpcFetch(proxy?: string): typeof fetch {
return envdRpcFetch
}

export function getEnvdConnectionLimit(): number {
return parsePositiveIntEnv(
'E2B_ENVD_CONNECTIONS',
DEFAULT_ENVD_CONNECTION_LIMIT
Comment thread
AdaAibaby marked this conversation as resolved.
)
}

export function getEnvdRpcConnectionLimit(): number {
return parsePositiveIntEnv(
'E2B_ENVD_RPC_CONNECTIONS',
Expand Down
17 changes: 17 additions & 0 deletions packages/js-sdk/tests/envd/http2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ afterEach(() => {
vi.resetModules()
vi.doUnmock('undici')
vi.doUnmock('../../src/utils')
delete process.env.E2B_ENVD_CONNECTIONS
delete process.env.E2B_ENVD_RPC_CONNECTIONS
delete process.env.E2B_ENVD_INFLIGHT_REQUESTS
delete process.env.E2B_ENVD_RPC_INFLIGHT_REQUESTS
Expand Down Expand Up @@ -158,6 +159,22 @@ test('can create a bounded dispatcher for RPC streams', async () => {
expect(agents).toEqual([{ allowH2: true, connections: 100 }])
})

test('reads envd connection limit from env', async () => {
process.env.E2B_ENVD_CONNECTIONS = '50'

const { getEnvdConnectionLimit } = await import('../../src/envd/http2')

expect(getEnvdConnectionLimit()).toBe(50)
})

test('getEnvdConnectionLimit throws on malformed env value', async () => {
process.env.E2B_ENVD_CONNECTIONS = 'bogus'

const { getEnvdConnectionLimit } = await import('../../src/envd/http2')

expect(() => getEnvdConnectionLimit()).toThrow(/E2B_ENVD_CONNECTIONS/)
})

test('reads RPC stream dispatcher connection limit from env', async () => {
process.env.E2B_ENVD_RPC_CONNECTIONS = '200'

Expand Down