Skip to content

fix: await async callbacks in CommandHandle.wait()#1261

Open
YizukiAme wants to merge 3 commits intoe2b-dev:mainfrom
YizukiAme:fix/await-async-callbacks
Open

fix: await async callbacks in CommandHandle.wait()#1261
YizukiAme wants to merge 3 commits intoe2b-dev:mainfrom
YizukiAme:fix/await-async-callbacks

Conversation

@YizukiAme
Copy link
Copy Markdown

Fixes #1259

Problem

The CommandHandle.wait() method fires onStdout, onStderr, and onPty callbacks without await, so async callbacks run as fire-and-forget microtasks. If a callback performs I/O (e.g. writing to a file, sending over network), wait() can resolve before the callback finishes, leading to lost data or race conditions.

Fix

Add await before each optional-chain callback invocation:

-this.onStdout?.(stdout)
+await this.onStdout?.(stdout)

This is fully backwards compatible — await-ing a sync function's return value is a no-op.

Tests

3 parameterized test cases (stdout, stderr, pty) verify that wait() does not resolve until an async callback's promise settles.

This fix was developed with AI assistance and reviewed by a human.

Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 11, 2026

🦋 Changeset detected

Latest commit: 7e915b3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
e2b Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JS SDK wait() resolves before async stdout/stderr/PTY callbacks finish

1 participant