Skip to content

Commit 6815c8f

Browse files
committed
fix(js-sdk): stop waiting for stream close after command end event
On receiving the "end" event in iterateEvents(), call handleDisconnect() to abort the transport controller, then return from the generator to stop blocking on the stream. In handleEvents(), ignore iteration errors when a result has already been captured since the error is from the expected abort. After the generator exits, fire a .next() call on the events stream to trigger connectrpc's deadline timer cleanup — on platforms where abort propagates to the body reader (Deno) this clears the timer immediately; on Node.js (nodejs/undici#1940) it settles when the server closes the stream.
1 parent dc77742 commit 6815c8f

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

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

Lines changed: 15 additions & 2 deletions
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
220221
}
221222
// TODO: Handle empty events like in python SDK
222223
}
@@ -234,7 +235,19 @@ export class CommandHandle
234235
}
235236
}
236237
} catch (e) {
237-
this.iterationError = handleRpcError(e)
238+
if (!this.result) {
239+
this.iterationError = handleRpcError(e)
240+
}
241+
}
242+
// Trigger connectrpc's deadline timer cleanup by forcing one more
243+
// .next() call on the events stream. On platforms where abort propagates
244+
// to the body reader (Deno), this rejects and clears the timer via
245+
// connectrpc's abort() callback. On platforms where it doesn't (Node.js
246+
// per nodejs/undici#1940), this settles when the server closes the stream.
247+
if (this.result) {
248+
this.events[Symbol.asyncIterator]()
249+
.next()
250+
.catch(() => {})
238251
}
239252
}
240253
}

0 commit comments

Comments
 (0)