Skip to content

Add non-waking container fetch method - #212

Closed
ghostwriternr wants to merge 1 commit into
cloudflare:mainfrom
ghostwriternr:non-waking-container-forward
Closed

Add non-waking container fetch method#212
ghostwriternr wants to merge 1 commit into
cloudflare:mainfrom
ghostwriternr:non-waking-container-forward

Conversation

@ghostwriternr

@ghostwriternr ghostwriternr commented May 18, 2026

Copy link
Copy Markdown
Member

Some request paths need to proxy traffic only when a container is already available. The Sandbox SDK preview URL path is one example: stale preview URL requests should be rejected without waking or starting a stopped container. Other passive traffic, health-adjacent routing, or authorization-gated proxy paths have the same requirement.

Today the Container class exposes fetch() and containerFetch() for forwarding, but both start the container and wait for ports before proxying the request. That makes callers choose between accidentally waking containers or duplicating the base class's forwarding logic.

This adds fetchIfRunning() as a non-waking forwarding primitive. It forwards only when the container is already running and marked healthy, and otherwise returns without starting, probing, or waiting for ports. containerFetch() now shares the same internal forwarding helper after its existing start/wait behavior succeeds, so HTTP, WebSocket, activity timeout, and inflight request accounting stay consistent across both paths.

Expose fetchIfRunning so callers can proxy to an already healthy
container without using wake-capable fetch paths. This lets consumers
serve passive traffic without accidentally starting stopped containers.
@ghostwriternr
ghostwriternr requested a review from a team as a code owner May 18, 2026 11:58
@ghostwriternr ghostwriternr changed the title Add fetchIfRunning to Container Add non-waking container fetch method May 18, 2026
@pkg-pr-new

pkg-pr-new Bot commented May 18, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@cloudflare/containers@212

commit: 34c61b5

@ghostwriternr

Copy link
Copy Markdown
Member Author

For the time being, I've inlined this + some necessary but acceptable duplication into the sandbox sdk itself in cloudflare/sandbox-sdk#708. This will let us properly validate that this is useful, and useful enough in this exact shape beyond what we're currently doing with it, before expanding API surface area in such critical code paths.

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.

1 participant