Skip to content

Disable Nagle on accepted HTTP streaming connections - #929

Merged
ashhart merged 4 commits into
ashhart:mainfrom
akol1:codex/http-stream-nodelay
Oct 18, 2026
Merged

ashhart merged 4 commits into
ashhart:mainfrom
akol1:codex/http-stream-nodelay

Conversation

@akol1

@akol1 akol1 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Accepted HTTP connections retain Nagle buffering, which can delay small incremental response writes. Set TCP_NODELAY before handing an accepted connection to the server; close and retry if configuration fails.

Real IPv4/IPv6 loopback tests check the accepted socket option. Their accept wait now has a stop watchdog, with a no-client regression that exercises timeout shutdown. The watchdog joins on every return. This is a socket-option and test-liveness change; no measured streaming-latency improvement is claimed.

Source: 7b94b5e6d20a4a18b7d8d4707e6c640049044958; current main base: b090e3b19014bfa1eb2b7f38ea3cc4d39abec9be. Zig 0.17.0, macOS arm64:

  • zig build native -Dcpu=apple_m1 -Dversion=1.0.0: 45/45 steps succeeded.
  • zig build test test-kernel-contract test-golden fuzz-cortheon -Dcpu=apple_m1: 214/214 steps succeeded; 3,018/3,028 tests passed, ten explicit skips.
  • Frozen server corpus: 309/319 equal, ten documented known differences, zero unexpected differences.
  • Whole-tree Zig formatting and whitespace checks pass. Lean: 517 inherited findings on base and head, zero new.

Current-head public CI: all four checks pass (format, desktop, mobile, and the Linux No GPU workflow). The Linux run executes the IPv4/IPv6 socket-option and no-client watchdog tests through the standard host root. No GPU kernel changes.

@cwschroeder cwschroeder left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Source review of 4e31bd79: no blocking issue found. The listener keeps ownership until socket configuration succeeds, closes the accepted descriptor on failure, and checks stop again on the next iteration. After handoff, the server retains its existing connection cleanup.

The refreshed Linux qualification has completed successfully: No GPU run, on this exact head. All four upstream checks are green. The new IPv4/IPv6 test is imported through server/root.zig and included in Linux zig build test, so the description's pending-Linux note can be updated.

One nonblocking test improvement: bound the wait for accept. If socket configuration fails, production correctly closes and retries, but the test's permanently false stop flag leaves it waiting for another client. A bounded stop watchdog would turn that case into a useful test failure.

The evidence proves the socket option is enabled; a streaming-latency gain remains unmeasured.

@akol1

akol1 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the liveness review. Fixed in 7b94b5e6: both accepted-stream checks use a bounded stop watchdog, and a no-client regression exercises the timeout path. The timer exits promptly after success and is joined before its state leaves scope.

At head 7b94b5e6d20a4a18b7d8d4707e6c640049044958, base b090e3b19014bfa1eb2b7f38ea3cc4d39abec9be, the native build and all four published host targets pass on macOS with Zig 0.17.0: 214/214 host steps, 3,018 passed and ten skipped tests, zero unexpected golden differences, zero added lean findings. The description now records the previous Linux success accurately and leaves the new watchdog's Linux result to current-head CI. No latency gain is claimed.

@cwschroeder cwschroeder left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scoped watchdog re-review of 7b94b5e6: the nonblocking liveness note from my earlier review is addressed. Astra found no new material issue in this test delta.

The actual listener root passes all seven tests in Debug and Fast on macOS arm64 with Zig 0.17.0, including accepted IPv4/IPv6 TCP_NODELAY and the no-client path. In a temporary source copy, removing only the watchdog stop request makes the direct no-client test executable exceed an external three-second limit; the unchanged implementation passes. Only that owned test process was terminated.

The watchdog remains alive until join on both success and timeout. The 20-ms parameter requests stop; the existing 200-ms polling controls when accept observes it, so this is no exact-deadline or latency claim. Whole-tree format, whitespace and lean pass (517/517 against main 6ee828c2, zero new). All four current-head checks, including Linux No GPU, are green. This rechecks the bounded test behavior and socket option, with no measured serving-latency improvement.

@ashhart
ashhart merged commit 01ead20 into ashhart:main Oct 18, 2026
4 checks passed
@ashhart

ashhart commented Oct 18, 2026

Copy link
Copy Markdown
Owner

Thank you, @akol1, for bounding the accepted-stream check and joining its watchdog before return.

We merged your work for 1.1.0 in 01ead20. The listener owns an accepted descriptor until TCP_NODELAY succeeds, closing it on failure before accepting another connection.

The change sets the socket option and keeps the test's state alive for its watchdog. We have not attached a latency improvement claim.

Posted by Ash's AI Assistant Synthena

BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…LAY), so streamed tokens leave as they are written
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.

3 participants