Skip to content

Fix WS stream timeout killing long-running streams#400

Open
whoiskatrin wants to merge 1 commit intomainfrom
fix/ws-stream-idle-timeout
Open

Fix WS stream timeout killing long-running streams#400
whoiskatrin wants to merge 1 commit intomainfrom
fix/ws-stream-idle-timeout

Conversation

@whoiskatrin
Copy link
Collaborator

Summary

  • Convert WebSocket streaming timeout from a fixed 2-minute total-duration timeout to an inactivity-based idle timeout (default: 5 minutes) that resets on every chunk, so execStream and process log streams stay alive as long as data is flowing
  • Make both requestTimeoutMs (non-streaming, default 2min) and streamIdleTimeoutMs (streaming, default 5min) user-configurable via SandboxOptions.transportTimeouts or environment variables (SANDBOX_REQUEST_TIMEOUT_MS, SANDBOX_STREAM_IDLE_TIMEOUT_MS)

Closes #398

The WebSocket transport applied a fixed 2-minute total-duration timeout
to streaming requests, breaking execStream and process log streams that
run longer than 2 minutes. Convert to an inactivity-based idle timeout
(default 5 minutes) that resets on every chunk, and make both the
request and stream idle timeouts user-configurable via SandboxOptions
or environment variables.

Closes #398
@changeset-bot
Copy link

changeset-bot bot commented Feb 18, 2026

🦋 Changeset detected

Latest commit: 326eebc

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

This PR includes changesets to release 1 package
Name Type
@cloudflare/sandbox 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

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

OpenCode Review

The timeout fix looks solid. Converting from total duration to idle timeout makes sense for long-running streams - agents and interactive processes should stay alive as long as they're producing output.

The implementation correctly separates streaming and non-streaming timeouts, with proper timer reset logic on every chunk. The configuration approach through both options and environment variables follows the existing pattern.

Environment variable parsing includes proper validation (positive integers only), and the defaults (2min for requests, 5min for stream idle) are reasonable for production use.

The timeout cleanup is handled consistently across all code paths (resolve, reject, error), preventing memory leaks from dangling timers.

Looks good to merge.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 18, 2026

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/sandbox-sdk/@cloudflare/sandbox@400

commit: 326eebc

@github-actions
Copy link
Contributor

🐳 Docker Images Published

Default:

FROM cloudflare/sandbox:0.0.0-pr-400-8bc899d

With Python:

FROM cloudflare/sandbox:0.0.0-pr-400-8bc899d-python

With OpenCode:

FROM cloudflare/sandbox:0.0.0-pr-400-8bc899d-opencode

Version: 0.0.0-pr-400-8bc899d

Use the -python variant if you need Python code execution, or -opencode for the variant with OpenCode AI coding agent pre-installed.


📦 Standalone Binary

For arbitrary Dockerfiles:

COPY --from=cloudflare/sandbox:0.0.0-pr-400-8bc899d /container-server/sandbox /sandbox
ENTRYPOINT ["/sandbox"]

Download via GitHub CLI:

gh run download 22148273705 -n sandbox-binary

Extract from Docker:

docker run --rm cloudflare/sandbox:0.0.0-pr-400-8bc899d cat /container-server/sandbox > sandbox && chmod +x sandbox

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.

ws-transport sets unconfigurable 120000ms timeout, breaking long running execStream

1 participant

Comments