Skip to content

loom route: the non-stream branch waits for the body with no bound, so an upstream that says one line and stalls holds the client for up to 3600 s #3268

Closed

Description

@bong-water-water-bong

What

forward_loom now bounds the wait for the first bytes (60 s, kLoomFirstByteSecs, engine#3254/#3262), and that bound is real for an upstream that says nothing. It does not cover the next step: once the first bytes classify as not a stream, the handler waits for the rest of the body with no bound at all —

if (shape != loom::StreamShape::Sse) {
    upstream->wait();          // <- no bound; the client's read timeout is 3600 s (set four lines above)

so an upstream that sends one complete non-SSE line ({"error":…}, an HTML error page) and then goes quiet without terminating the body holds the connection with no status line sent, for as long as the read timeout. That is the same failure the 60 s bound was added to remove, one branch over.

Measured

Stub loom-serve that answers one complete non-SSE line and then holds the body open; the handler's loop copied verbatim from app/serve.cpp with the shipped constants (kLoomFirstByteSecs = 60, set_read_timeout(3600)), and loom_stream_shape from app/loom_route.h. No engine build, no device, ephemeral port:

first bytes at 0.00 s, 26 bytes, shape=NotSse
NON-STREAM BRANCH: upstream->wait() blocked 70.0 s AFTER the status was known
bound=60 s, stall=70 s -> the 60 s bound does NOT cover this branch
BOUNDED VARIANT: status known at 0.00 s; future was still running -> stop(); total 2.00 s

So the handler waits exactly as long as the upstream stalls (70 s here), not 60, and the last line shows the fix is cheap: wait_for against a deadline plus the abort_upstream() that already exists released the same case in 2.00 s (that run used a 2 s test bound).

Provenance: ~/.cache/scratch-cl-game/probe-3254/probe.cpp (130 lines, Apache header). It is the control flow, not the engine binary, so it proves the guarantee and not real loom-serve behaviour; the real-binary check is a gate row with a stalling fake upstream, which does not exist yet.

Fix shape

The non-stream branch should bound the body wait with the same constant and the same cancellation path:

if (upstream->wait_for(std::chrono::seconds(kLoomFirstByteSecs)) != std::future_status::ready) {
    abort_upstream();                      // shared Client::stop() -> the Post() returns promptly
    res.status = 504;                      // and say which case it was, like the first-byte 504 does
    …
    return;
}

Not claimed

  • No device run and no engine build; nothing here is a kernel or route-perf claim.
  • The 60 s figure is a choice, not a measurement of loom-serve: a refusal body is small, so any bound above the first-byte one would do — it is named here because it is the constant already in the file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions