Skip to content

fix: ensure streaming requests have default timeout when request_timeout is None#1227

Open
YouFoxGirl wants to merge 1 commit intoe2b-dev:mainfrom
YouFoxGirl:fix-1128-streaming-timeout
Open

fix: ensure streaming requests have default timeout when request_timeout is None#1227
YouFoxGirl wants to merge 1 commit intoe2b-dev:mainfrom
YouFoxGirl:fix-1128-streaming-timeout

Conversation

@YouFoxGirl
Copy link

@YouFoxGirl YouFoxGirl commented Mar 22, 2026

Summary

Fixes #1128 — streaming requests hang indefinitely when sandbox is unreachable

When calling streaming RPC methods (e.g. commands.run) without an explicit request_timeout, the request would hang indefinitely if the sandbox became unreachable - because only connect/pool timeouts were set, not read/write.

The fix makes streaming requests fall back to the per-command timeout parameter (which defaults to 60s) for connect/pool/write when request_timeout is not set. This matches the behavior of unary RPC calls which already set all four timeout types.

Changes

In e2b_connect/client.py, _prepare_server_stream_request:

  • When request_timeout is None (the default), fall back to timeout for connect/pool/write timeouts
  • When request_timeout is explicitly provided, it still takes precedence (existing behavior)

Added unit test verifying both cases.

…out is None

When calling streaming RPC methods (e.g. commands.run) without an explicit
request_timeout, the request would hang indefinitely if the sandbox became
unreachable - because only connect/pool timeouts were set, not read/write.

The fix makes streaming requests fall back to the per-command timeout
parameter (which defaults to 60s) for connect/pool/write when request_timeout
is not set. This matches the behavior of unary RPC calls which already set
all four timeout types.

Fixes e2b-dev#1128
@changeset-bot
Copy link

changeset-bot bot commented Mar 22, 2026

⚠️ No Changeset found

Latest commit: 2a5343f

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

Copy link

@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: 2a5343f7e1

ℹ️ 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".

timeout_ext["connect"] = request_timeout
timeout_ext["pool"] = request_timeout
timeout_ext["write"] = request_timeout
elif timeout is not None:

Choose a reason for hiding this comment

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

P1 Badge Preserve unlimited semantics when timeout is set to 0

This new fallback runs whenever request_timeout is None, including when callers pass timeout=0 (documented elsewhere in the SDK as “no limit”). In that case this branch now sets connect/pool/write to 0, which in httpcore/httpx timeout extensions is treated as an immediate timeout rather than unlimited, so streaming calls can fail instantly instead of remaining unbounded. The regression occurs when users disable request timeouts (request_timeout=0/None) and rely on timeout=0 for long-lived streams.

Useful? React with 👍 / 👎.

client = Client(
url="http://localhost:8080",
response_type=MagicMock,
json=True,

Choose a reason for hiding this comment

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

P2 Badge Use a protobuf-compatible message in the new regression test

This test configures Client(..., json=True), so _prepare_server_stream_request uses JSONCodec.encode (json_format.MessageToJson), which expects a real protobuf message object with protobuf metadata (e.g. DESCRIPTOR). FakeMsg only defines SerializeToString, so the test will raise before reaching the timeout assertions once protobuf/http deps are present, making the regression test ineffective.

Useful? React with 👍 / 👎.

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.

[Bug]: commands.run hangs indefinitely when sandbox becomes unreachable — request_timeout does not set read timeout on streaming calls

1 participant