Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Explicitly configure keepalive pinging

Tomas Valenta71406236c065
diff --git a/packages/js-sdk/src/connectionConfig.ts b/packages/js-sdk/src/connectionConfig.ts
index a4f908038..e325008d0 100644
--- a/packages/js-sdk/src/connectionConfig.ts
+++ b/packages/js-sdk/src/connectionConfig.ts
@@ -2,6 +2,7 @@ import { Logger } from './logs'
import { getEnvVar } from './api/metadata'
const REQUEST_TIMEOUT_MS = 30_000 // 30s
+export const KEEPALIVE_PING_INTERVAL_SEC = 50 // 50s
export interface ConnectionOpts {
apiKey?: string
diff --git a/packages/js-sdk/src/sandbox/filesystem/index.ts b/packages/js-sdk/src/sandbox/filesystem/index.ts
index 0c20681d2..e2af154dd 100644
--- a/packages/js-sdk/src/sandbox/filesystem/index.ts
+++ b/packages/js-sdk/src/sandbox/filesystem/index.ts
@@ -10,6 +10,7 @@ import {
defaultUsername,
Username,
ConnectionOpts,
+ KEEPALIVE_PING_INTERVAL_SEC,
} from '../../connectionConfig'
import { handleEnvdApiError, handleWatchDirStartEvent } from '../../envd/api'
@@ -244,7 +245,10 @@ export class Filesystem {
: undefined
const events = this.rpc.watchDir({ path }, {
- headers: authenticationHeader(opts?.user),
+ headers: {
+ ...authenticationHeader(opts?.user),
+ 'Keepalive-Ping-Interval': KEEPALIVE_PING_INTERVAL_SEC.toString(),
+ },
signal: controller.signal,
timeoutMs: opts?.timeout ?? this.defaultWatchTimeout,
})
diff --git a/packages/js-sdk/src/sandbox/process/index.ts b/packages/js-sdk/src/sandbox/process/index.ts
index 66670a857..f26a3fe0c 100644
--- a/packages/js-sdk/src/sandbox/process/index.ts
+++ b/packages/js-sdk/src/sandbox/process/index.ts
@@ -12,7 +12,7 @@ import {
Signal,
ProcessConfig,
} from '../../envd/process/process_pb'
-import { ConnectionConfig, Username, ConnectionOpts } from '../../connectionConfig'
+import { ConnectionConfig, Username, ConnectionOpts, KEEPALIVE_PING_INTERVAL_SEC } from '../../connectionConfig'
import { authenticationHeader, handleRpcError } from '../../envd/rpc'
import { ProcessHandle, ProcessResult } from './processHandle'
import { handleProcessStartEvent } from '../../envd/api'
@@ -136,6 +136,9 @@ export class Process {
},
}, {
signal: controller.signal,
+ headers: {
+ 'Keepalive-Ping-Interval': KEEPALIVE_PING_INTERVAL_SEC.toString(),
+ },
timeoutMs: opts?.timeoutMs ?? this.defaultProcessConnectionTimeout,
})
@@ -187,7 +190,10 @@ export class Process {
args: ['-l', '-c', cmd],
},
}, {
- headers: authenticationHeader(opts?.user),
+ headers: {
+ ...authenticationHeader(opts?.user),
+ 'Keepalive-Ping-Interval': KEEPALIVE_PING_INTERVAL_SEC.toString(),
+ },
signal: controller.signal,
timeoutMs: opts?.timeoutMs ?? this.defaultProcessConnectionTimeout,
})