Commit Graph
15 Commits
Author SHA1 Message Date
BFlat 14935838a5 Merge pull request #2626 from dotCooCoo/fix/control-protocol-first-line-deadline
craft-control-protocol: serve_tcp closes a connection that sends no request in time
2026-11-28 11:48:06 +07:00
dotCooCoo 335208a614 Control protocol: test that blank lines do not extend the first-request deadline 2026-11-26 00:16:21 -08:00
dotCooCoo 10133885f1 Merge main into fix/control-protocol-first-line-deadline 2026-11-25 19:52:15 -08:00
dotCooCoo 9c0298ef46 Merge main into feat/control-protocol-new-token 2026-11-25 19:30:12 -08:00
BFlat 7e92cb2f6d Merge pull request #3120 from dotCooCoo/fix/control-line-reader-behavior
craft-control: the server's line reader frames request lines as craft-control-protocol's does
2026-11-26 10:26:22 +07:00
dotCooCoo 5cd5f78e1e craft-control-protocol: the line cap does not count the line's \r\n
read_bounded_line read at most max + 1 bytes, so a line of exactly max
bytes followed by \r\n stopped after the \r and was refused, while the
same line followed by \n was read. It now reads up to max + 2 bytes,
strips the \n and a \r before it, and then checks the line against max.
A line of max + 1 bytes is still refused with either ending.
2026-11-22 15:51:15 -08:00
dotCooCoo 513526a4dc craft-control-protocol: send no rejection reply after the first-request deadline
A line that is read before the first request is admitted but completes
after the first-request deadline is no longer answered with an error
reply when it is not a request (bad JSON, a failed token check or an
oversized line). serve_tcp closes the connection without a reply, as it
does for a request read after the deadline.
2026-11-20 14:39:26 -08:00
dotCooCoo ed13755385 craft-control-protocol: check the first-request deadline before admitting a request
A request read just after the deadline, for example because the thread
paused between the deadline check and the socket read, was admitted and
dispatched. admit now returns TimedOut when the deadline has passed and
leaves it in place, so the connection closes without a reply.

Tests: a request admitted at the deadline is refused, and a read after
the deadline fails even with input waiting on the socket, so input that
arrives before each read does not extend the deadline.
2026-11-20 11:13:20 -08:00
dotCooCoo a168d6c376 craft-control-protocol: serve_tcp closes a connection that sends no request in time
serve_tcp serves one TCP connection with the same framing and
authentication as serve_lines, and gives the peer a deadline for its
first authenticated request. Every read before that request shares the
one deadline, so blank lines or a line sent a byte at a time do not
extend it. When it passes, the connection closes with no reply and
nothing is dispatched. After the first request, each read waits at most
the idle time the caller passes.

serve_lines waits for the first line as long as the caller's read
timeout, so a local connection that never sends a request keeps its
connection slot for that whole time.
2026-11-20 10:52:18 -08:00
dotCooCoo 6e3c3065e8 control-protocol: generate session tokens that valid_token accepts
new_token returns 32 bytes from the operating system's random source as
64 lowercase hexadecimal characters, the form valid_token checks. A
server built on serve_lines can now create its per-launch token without
its own random source. The function and its getrandom dependency are
left out on wasm32.
2026-11-20 10:44:17 -08:00
dotCooCoo 1f52a13a8e craft-control-protocol: write reply lines through a buffer
serve_lines wrote replies with writeln!, which hands the writer every
string, number and separator of the JSON value as a separate write. On
an unbuffered TcpStream that is one system call per piece. Replies and
the closing rejection now go through a 64 KiB BufWriter and are flushed
once per line, so a small reply is one write and a large one is a few
buffer-sized writes without a second whole copy in memory.
2026-11-20 10:43:52 -08:00
Dylan M. Taylor e2b5907a40 Test control framing failures and backpressure 2026-11-15 19:05:00 +00:00
Dylan M. Taylor edfd24c004 Share control client request and reply grammar 2026-11-15 19:00:31 +00:00
Dylan M. Taylor 2e6878d973 Share session token shape validation 2026-11-15 18:59:28 +00:00
Dylan M. Taylor 82276297a6 Share authenticated JSON-lines control protocol 2026-11-15 18:57:52 +00:00