Skip to content

tcp: sendTimeoutMs's doc says it's a deadline for each flush, on purpose, and readTimeoutMs's says when its clock runs - #50

Merged
MDA2AV merged 1 commit into
mainfrom
docs/send-timeout
Nov 8, 2026
Merged

MDA2AV merged 1 commit into
mainfrom
docs/send-timeout

Conversation

@MDA2AV

@MDA2AV MDA2AV commented Nov 8, 2026

Copy link
Copy Markdown
Owner

Fixes #24. Docs only.

What was wrong

sendTimeoutMs was documented as "how long a flush may wait on a peer that stopped draining", which reads as a stall timer. It is a deadline for the whole flush: the clock starts when the flush is handed over, and nothing moves it until the flush completes. So a peer that keeps reading, but slowly, is cut off once one flush takes longer than the timeout. #24 measured that: 12 MiB to a peer reading about 0.77 MiB/s, with the timeout at 1 s, got 2.28 MiB through.

Why the behavior stays

A clock that restarted on progress, as #24's first two fix options proposed, would let a peer that reads a little now and then hold a flush open for as long as it likes, and with it the connection and the slab holding the body. That's a slow-read attack. A deadline per flush bounds it, and nothing the peer sends restarts that deadline. ioxide made the same choice, and its SendTimeoutMs doc says so.

What changed

  • sendTimeoutMs: says it's a deadline for the whole flush and what it defends against. It also says how to send a large body to a slow peer: flush it in pieces, each with its own deadline. The peer then only has to keep up the piece size per timeout, about 1 KiB/s for 64 KiB pieces at the default 60 s.
  • readTimeoutMs: says when its clock runs: only while a read waits with nothing queued, and a flush restarts it. So a handler that is busy, sending or not reading is never timed out by it. It also says the timeout bounds a peer's close after its handler let go, and that disableReadTimeout takes a connection's reads off it.
  • The sweep's comment said "one whose send the peer stopped draining", and now says what it checks.

TcpTimeoutTest already covers the behavior these describe, for example a server that keeps sending is not waiting on its peer and a handler busy for longer than the read timeout still answers.

🤖 Generated with Claude Code

…ose, and readTimeoutMs's says when its clock runs (#24)

sendTimeoutMs read as a stall timer, "how long a flush may wait on a peer that stopped draining", so a slow peer cut
off by a large flush looked like a bug. It is a deadline for the whole flush, and that is wanted: a clock that
restarted on progress would let a peer that reads a little now and then hold a flush and its slab open for good. The
doc now says so, as ioxide's does, with the way to send a large body to a slow peer: in pieces.

readTimeoutMs says when its clock runs: only while a read waits with nothing queued, and a flush restarts it.
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.

sendTimeoutMs's doc says it waits on a peer that stopped draining, but it's a deadline for each flush

1 participant