Skip to content

Add a per-route request deadline for long streams - #10

Merged
renerocksai merged 5 commits into
mainfrom
feat/per-route-deadline
Sep 25, 2026
Merged

renerocksai merged 5 commits into
mainfrom
feat/per-route-deadline

Conversation

@renerocksai

@renerocksai renerocksai commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Depends on bounded/http PR #7.
This branch pins that engine PR's head dae8961, as Baz PR #6 did for engine PR #5.
After engine #7 merges, move the pin to the engine's merged main commit (URL, commit and package hash together in build.zig.zon, plus docs/DEPENDENCY.md).
Rebased onto main after #11.

Problem

server.timeout_ms bounds every request, including SSE streams.
A stream needs minutes, but raising the global value lets any stalled request hold a connection that long.
The omajot hub (a Baz app behind tailscale serve) hit this with its SSE doorbell.

API

// Server options
.server = .{ .timeout_ms = 5000, .max_timeout_ms = 10 * 60 * 1000 },

// Only this route gets the long deadline
try app.routeContinuation("GET", "/events", State, start, advance, .{ .timeout_ms = 10 * 60 * 1000 });
  • RouteOptions.timeout_ms: ?u32 = null works for routeWith, routeContinuation, bindWith and endpointWith.
  • Registration returns error.InvalidRouteTimeout for zero, or for a value above server.max_timeout_ms (default 0, disabled).
  • Baz asks the engine for the deadline before route middleware, and before a continuation starts.
  • The deadline counts from the request start. The next request on the connection uses the default again, which the engine enforces.

Idle keep-alive time (found with #11)

tailscale serve reuses idle backend connections. Before, the idle time counted toward the next request's deadline, so streams ended early.
Engine #7 now starts a request deadline at its first byte, and the new server.idle_timeout_ms bounds idle time separately (0 = timeout_ms).
docs/HTTPS.md replaces its "Current limit" paragraph with the fixed behavior. LIMITS.md and SSE.md describe the new start point.
continuations_integration.py adds a stream after 2.5 s idle on a kept-alive connection with a 3 s default, in both modes.

Changes

  • src/App.zig: option, validation, application, and a registration unit test.
  • examples/continuations.zig: /long-stream (two 2-second pauses, 10-second route timeout, 3-second server default).
  • tests/continuations_integration.py: the long stream completes after more than 3.5 s and the connection stays usable, in inline and worker execution.
  • Docs: LIMITS.md row, a new SSE.md section, notes in STREAMING.md and MIDDLEWARE.md, and the pin record in DEPENDENCY.md.

Verification (Linux omarx1, exact Zig 0.16.0)

  • zig build verify in Debug and ReleaseSafe: 70/70 steps, 245/245 tests each.
  • zig build install examples -Doptimize=ReleaseSafe: ok.
  • After rebase: verify ReleaseSafe 71/71 steps, 245/245 tests; continuations 24, examples 23, cli 78, jobs 22; site check passes (27 examples).
  • Before rebase, integration suites, all passing: continuations 24 (including 4 new), jobs 22, app 14, examples 22, streaming 14, middleware 15, cli 76, borrow 9, cookies 14, sessions 17, mustache 12.
  • tools/build_pages.py and tools/check_site.py: pass.

macOS and Windows for Baz rely on hosted CI.
The engine PR records native macOS (kqueue) results for the engine change itself.

Follow-up (not in this PR)

When the deadline expires, the engine closes a chunked stream without the terminating 0\r\n\r\n.
Browsers reconnect with Last-Event-ID, but std.http.Client reports ReadFailed.
A later engine change could end the stream cleanly at a chunk boundary.

🤖 Generated with Claude Code

@renerocksai
renerocksai force-pushed the feat/per-route-deadline branch from fc78e36 to 63f9f18 Compare September 25, 2026 16:54
renerocksai and others added 4 commits September 25, 2026 18:58
`RouteOptions.timeout_ms` gives one route its own deadline in place of
`server.timeout_ms`. Registration requires `server.max_timeout_ms` to cover
the value and rejects it otherwise with `error.InvalidRouteTimeout`. Baz asks
the engine for the deadline before route middleware and continuation start.

The continuations example adds `/long-stream`, which outlives the 3-second
server deadline. Its integration case checks both execution modes and the
following keep-alive request.

Pins bounded/http PR #7 (`96c249b`), which adds `Config.max_timeout_ms` and
`Context.setRequestTimeout`.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
bounded/http PR #7 now starts a request deadline at the request's first
byte and bounds idle keep-alive time with `idle_timeout_ms`. Idle time no
longer shortens a following request or stream.

LIMITS.md and SSE.md describe the new start point and the idle bound. The
continuations suite adds a stream that follows 2.5 idle seconds on a
kept-alive connection with a 3-second default.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A request deadline now starts at the request's first byte, so pooled
tailscale serve connections no longer shorten streams. The guide keeps the
earlier measurements as history and points to RouteOptions.timeout_ms.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@renerocksai
renerocksai force-pushed the feat/per-route-deadline branch from 63f9f18 to 695410b Compare September 25, 2026 17:04
bounded-http PR #7 is merged; pin its merge commit 874a8f3 on main
instead of the branch head dae8961. The package hash is unchanged: the
merged tree is the one verified on the branch.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@renerocksai
renerocksai merged commit b2aa45f into main Sep 25, 2026
8 checks passed
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