Harden fd-daemon client reads with timeout#13
Conversation
|
Good defensive direction (a read timeout closes the slow-loris/hang vector). No blockers, but a few things to tighten before merge:
(Reviewed with the lab's tri-brain pass — Codex + Grok.) |
…EOF distinction 1. Configurable timeout via FD_READ_TIMEOUT env var (default 5s). 2. Check fd_sock_set_read_timeout return value; warn on failure. 3. read_full now returns 0 (EOF), -1 (timeout), or 1 (success) so serve_client can distinguish clean disconnect from staled client. 4. All read_full callers in serve_client updated accordingly.
Addressed review feedback (round 2)Thanks @Scottcjn for the detailed review. Here's what changed: 1. Return value check ✅d_sock_set_read_timeout() return is now checked. On failure, a warning is logged to stderr but execution continues (failing closed would break existing deployments where the platform's socket defaults already work). The daemon now at least signals the misconfiguration. 2. Configurable timeout ✅Hardcoded 5s is now configurable via the FD_READ_TIMEOUT environment variable (seconds, default 5). Matches the existing FD_PORT/FD_THREADS config pattern. Setting FD_READ_TIMEOUT=0 disables the timeout entirely (useful for debuggers or large scene uploads over slow links). 3. Timeout vs disconnect distinction ✅ead_full() return type changed from �ool to long:
|
Problem
fd-daemonserves one client at a time. A client can send a valid frame header with a nonzero payload length, then hold the socket open without completing the payload. The daemon blocks insideread_full()and never returns toaccept()while that peer stays connected.Fix
fd_sock_set_read_timeout()helper indaemon/fd_listen.h.serve_client().Not changed
Verification
Local static validation from the extracted source tree:
I could not run a full daemon build here because this Windows workspace does not have a C++ compiler available, and the repository's daemon build also expects the vendored POV-Ray archives/toolchain.
Bounty / claim context
Issue: #5
Possible bounty context: RustChain Bug Hunter Scottcjn/rustchain-bounties#520
Wallet:
RTC269fa5650798c3aa5086a128c025a546e0a41d0bAI assistance disclosure: this PR was prepared with AI assistance and manually validated against the source files and checks listed above.