Skip to content

feat: end a stream that goes silent instead of waiting out the request - #133

Open
TiaraBasori wants to merge 1 commit into
jasonxu114514:mainfrom
TiaraBasori:feat/stream-idle-watchdog
Open

TiaraBasori wants to merge 1 commit into
jasonxu114514:mainfrom
TiaraBasori:feat/stream-idle-watchdog

Conversation

@TiaraBasori

Copy link
Copy Markdown
Contributor

An upstream that accepts a request and then stops sending leaves the forward loop parked on a read. Nothing downstream notices: the response headers are already sent, the first-event wait is long over, and the only remaining bound was (300s by default), so the client waited minutes for a stream that had already stalled.\n\n bounds silence inside an established stream.\n\n- The watchdog is armed per read and re-armed on every completed read, so a slow but active generation is never cut.\n- When it fires it closes the upstream body, which is what actually unblocks a read parked on a silent socket; canceling a context alone does not, because the body was opened under the request context.\n- The stall is classified before the client-cancel check on all three stream paths (ForwardStream, TranscodeStream, rotation), so the client gets an in-band error event explaining why the stream stopped, and the request is logged as instead of .\n- Default keeps the previous behavior; the docs note it should sit below .\n\nVerified against a real gateway binary and an upstream that sends one event and then holds the connection open: with and an idle timeout of 2s, the client received the first event, the error event and at 2046ms. A 400ms gap with a 300ms watchdog is cut; a 100ms gap is not; an actively ticking stream runs to completion untouched.

… request

An upstream that accepts a request and then stops sending holds the forward
loop on a parked read. Nothing downstream notices: the response headers are
already sent, the first-event wait is long over, and the only remaining bound
was the request-level timeout (retry.timeout_seconds, 300s by default). A
client therefore waited minutes for a stream that had already stalled.

performance.stream_idle_timeout_seconds bounds silence inside an established
stream. The watchdog is armed per read and re-armed on every completed read, so
a slow but active generation is never cut; when it fires it closes the upstream
body, which is what actually unblocks a read parked on a silent socket, and the
reader reports the stall as an upstream error.

The stall is classified before the client-cancel check in all three stream
paths: the watchdog does not touch the client, so the client is owed an in-band
error event explaining why the stream stopped. ForwardStream, TranscodeStream
and the rotation stream all emit one; the request is logged as stream_error.

Default 0 keeps the previous behavior.
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