Skip to content

fix: disable stream timeout for background commands to allow reconnect by PID#1229

Open
majiayu000 wants to merge 2 commits intoe2b-dev:mainfrom
majiayu000:fix/issue-1074-background-command-reconnect-timeout
Open

fix: disable stream timeout for background commands to allow reconnect by PID#1229
majiayu000 wants to merge 2 commits intoe2b-dev:mainfrom
majiayu000:fix/issue-1074-background-command-reconnect-timeout

Conversation

@majiayu000
Copy link
Copy Markdown

Fixes #1074

Summary

Commands.run() passes a default 60-second timeout to the internal start() RPC call. This timeout sets a Connect-RPC deadline on the server-streaming call. For background commands, when the deadline expires the stream terminates with DeadlineExceeded, which signals envd to clean up its process tracking — making the PID unreachable for subsequent connect(pid) calls.

This fix changes the default timeout for background commands to 0 (unlimited) while preserving the 60-second default for foreground commands:

  • JS SDK: When background is true and timeoutMs is not explicitly provided, override to 0 before calling start().
  • Python SDK (sync + async): Change the timeout parameter default from 60 to None (sentinel), then resolve to 0 for background commands or 60 for foreground commands at runtime.

Users who explicitly pass a timeout value still get that exact timeout regardless of background mode.

Test plan

  • Verified pnpm run typecheck, pnpm run lint, and pnpm run format all pass
  • Existing connect tests continue to pass
  • Manual verification: start a background command, wait >60s, then connect(pid) succeeds

…t by PID

When running background commands, the default 60s stream timeout caused
the RPC connection to terminate with DeadlineExceeded. This made envd
clean up process tracking, so subsequent connect(pid) calls would fail.

For background commands where timeout is not explicitly set, override to
0 (no timeout) so the process remains reachable for reconnection.

Fixes e2b-dev#1074

Signed-off-by: majiayu000 <1835304752@qq.com>
…default

Replace `timeout == 60` check with `timeout: Optional[float] = None`
sentinel to correctly distinguish 'user omitted timeout' from 'user
explicitly set timeout=60'. This preserves the user's explicit timeout
choice for background commands while defaulting to unlimited (0) when
no timeout is specified.

Signed-off-by: majiayu000 <1835304752@qq.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 23, 2026

⚠️ No Changeset found

Latest commit: bca54bd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@majiayu000 majiayu000 marked this pull request as ready for review March 23, 2026 00:54
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bca54bd625

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +223 to +224
if timeout is None:
effective_timeout = 0 if background else 60
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve explicit timeout=None for Python foreground runs

This branch now rewrites every timeout=None call to 60 when background is false, so commands.run(..., timeout=None) no longer disables the command-stream deadline. That is a public API regression, and it also changes existing internal callers such as packages/python-sdk/e2b/sandbox_sync/git.py:_run_git and packages/python-sdk/e2b/sandbox_async/git.py:_run_git, which default timeout to None and forward it directly. Slow git clone/fetch/push operations that previously had no command timeout will now start failing with TimeoutException after 60 seconds. If the goal is only to special-case omitted timeouts for background commands, this needs a separate sentinel instead of treating explicit None as “use default”.

Useful? React with 👍 / 👎.

@ValentaTomas ValentaTomas removed their request for review March 25, 2026 16:22
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.

Reconnect to running command by PID fails after 2 minutes

1 participant