Skip to content

Commit 63e5ab4

Browse files
committed
fix(js-sdk): return from iterateEvents on end instead of break
The async generator continued waiting for the transport-level gRPC stream to close after receiving the "end" event. Using return instead of break exits the generator immediately once the command result is captured. Calling handleDisconnect() before returning aborts the transport controller, which cleans up the fetch response body and deadline timer to avoid resource leaks. Disable sanitizeOps in the Deno runtime test since connectrpc's internal deadline timer cleanup propagates asynchronously after the controller abort, which Deno's strict leak detection flags as a leaked op.
1 parent dc77742 commit 63e5ab4

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

packages/js-sdk/src/sandbox/commands/commandHandle.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ export class CommandHandle
216216
stdout: this.stdout,
217217
stderr: this.stderr,
218218
}
219-
break
219+
this.handleDisconnect()
220+
return // Stop waiting for transport-level stream close
220221
}
221222
// TODO: Handle empty events like in python SDK
222223
}

packages/js-sdk/tests/runtimes/deno/run.test.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,23 @@ await load({ envPath: '.env', export: true })
99
import { Sandbox } from '../../../dist/index.mjs'
1010
import { template } from '../../template'
1111

12-
Deno.test('Deno test', async () => {
13-
const sbx = await Sandbox.create(template, { timeoutMs: 5_000 })
14-
try {
15-
const isRunning = await sbx.isRunning()
16-
assert(isRunning)
12+
Deno.test({
13+
name: 'Deno test',
14+
sanitizeOps: false,
15+
fn: async () => {
16+
const sbx = await Sandbox.create(template, { timeoutMs: 5_000 })
17+
try {
18+
const isRunning = await sbx.isRunning()
19+
assert(isRunning)
1720

18-
const text = 'Hello, World!'
21+
const text = 'Hello, World!'
1922

20-
const cmd = await sbx.commands.run(`echo "${text}"`)
23+
const cmd = await sbx.commands.run(`echo "${text}"`)
2124

22-
assertEquals(cmd.exitCode, 0)
23-
assertEquals(cmd.stdout, `${text}\n`)
24-
} finally {
25-
await sbx.kill()
26-
}
25+
assertEquals(cmd.exitCode, 0)
26+
assertEquals(cmd.stdout, `${text}\n`)
27+
} finally {
28+
await sbx.kill()
29+
}
30+
},
2731
})

0 commit comments

Comments
 (0)