Skip to content

fix(http1): refuse a non-blocking chunk from the outbound depth (#179) - #214

Merged
EdmondDantes merged 1 commit into
mainfrom
179-serialized-h1-outbound
Aug 22, 2026
Merged

EdmondDantes merged 1 commit into
mainfrom
179-serialized-h1-outbound

Conversation

@EdmondDantes

Copy link
Copy Markdown
Contributor

Closes #179.

tryWrite() answered true on every offer and parked the handler inside the
write, so the "refused — do something else" branch of a handler was dead code
on HTTP/1.

The fix splits the two callers rather than moving the whole path off the await.
write() keeps http_connection_send_strv_awaited, and with it the return
value that sets stream_dead, the bracketed write deadline and the copy-free
frame — the three things dev/BENCHMARKS.md and the #211 ruling refused to
give up. tryWrite() queues its frame on the connection's outbound tail and is
refused once the depth reaches setStreamWriteBufferBytes.

The depth is the tail plus the write in flight. Counting only the tail reads
zero for the whole first write, so the refusal arrives one write late and the
memory a slow peer pins is twice the knob.

Two things the awaited path had been providing came with the queued one:

  • A queued write learns nothing. libuv reports a failed write at
    completion, and a fire-and-forget completion carries no status, so EPIPE was
    invisible. The read side now latches write_failed and wakes anyone parked
    on the tail; is_alive, the terminator and send_raw all read it, so a body
    that failed is not sealed as one that finished.
  • Queued bytes have no await to time out. The connection's write deadline
    is armed when a non-blocking frame is submitted and stopped when the tail
    goes idle, so a peer that stops reading can no longer pin the connection
    through the destroy that defers on out_in_flight.

Evidence

h1/053 is restored from e5f91a1^, the commit that deleted it in #177
because HTTP/1 could not refuse: 42 chunks accepted against a peer that never
reads, the 43rd refused, the handler still running rather than parked.

h1/032 changes: it answers a refusal with awaitWritable(). The twins never
suspend, and a loop that only offers never gives the reactor the turn in which
the peer's RST arrives — the test's 499 rested on the hidden park this change
removes, and now rests on the yield a handler actually makes.

Full suite 461 tests, 438 passed, 0 failed, 0 warned, 23 skipped on absent tool
gates, two runs; ctest 16 of 16.

The design was attacked before it was written; the findings that shaped it are
the peer-gone latch, the tail deadline and the in-flight byte count above.

@github-actions

github-actions Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Total lines: 82.46% → 82.73% (+0.27 pp)

File Baseline Current Δ Touched
src/compression/http_compression_response.c 77.64% 78.27% +0.64 pp
src/core/http_connection.c 77.20% 77.62% +0.42 pp ●
src/core/http_connection.h 81.82% 81.82% +0.00 pp ●
src/core/http_connection_tls.c 73.74% 73.46% -0.28 pp
src/http1/http1_stream.c 75.58% 79.13% +3.54 pp ●
src/http2/http2_session.c 85.61% 88.76% +3.16 pp
src/http3/http3_callbacks.c 83.07% 83.39% +0.32 pp
src/http3/http3_listener.c 76.73% 76.88% +0.15 pp
src/http_body_stream.c 75.76% 84.85% +9.09 pp
src/http_request.c 80.96% 84.05% +3.09 pp
src/http_response.c 89.98% 89.77% -0.21 pp
src/http_sse.c 86.78% 87.67% +0.88 pp
src/websocket/php_websocket.c 78.44% 78.61% +0.17 pp
src/websocket/ws_session.c 89.48% 90.22% +0.74 pp

@EdmondDantes
EdmondDantes force-pushed the 179-serialized-h1-outbound branch from 9a1a41f to ad2c0ec Compare August 22, 2026 09:07
@EdmondDantes
EdmondDantes merged commit cb87357 into main Aug 22, 2026
8 checks passed
@EdmondDantes
EdmondDantes deleted the 179-serialized-h1-outbound branch August 22, 2026 09:19
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.

HTTP/1 writes a response through two channels, which blocks a non-blocking append

1 participant