Repository navigation
fix(h2): drive the h2c read-path drain through the connection emit (#219) - #220
Conversation
CoverageTotal lines: 82.76% → 82.72% (-0.04 pp)
❌ Regression in touched files (> 1.0 pp drop)
Add |
|
Adversarial review of the diff turned up four more defects, all reachable through this change. Fixed here rather than filed. Two drain cursors over one session. The error path still used A write completion finalised a deferred destroy before asking the session for its last frames. A session that finished while a write was in flight was never torn down. The emit handed its buffer and body references to the writev context without detaching them. A bailout in the submit — it allocates — then ran the caller's A chained submit that never reached the reactor left the in-flight state set. Pre-existing, and this change makes the error path lean on the deferred destroy it stranded. Separately, and found while measuring: one PING was answered with two ACKs — #222, fixed here with Two findings are left open because they are pre-existing and reach past this path: nothing arms a write deadline for the queued h2c path, so a peer that stops reading without closing wedges 467 phpt, 443 passed, 0 failed, 0 warned, 24 skipped; |
|
The second reviewer caught a regression I introduced in the previous commit, and it was visible in my own GOAWAY probe before that — I read past it. Moving the emit ahead of the deferred destroy was wrong, and is reverted. A bad connection preface answered What the reorder was for is done differently now. The third case — a deferred destroy discarding the response's own last frames — is filed as #225 rather than fixed here: it is
Two more from the same review, filed and not fixed here: #223 (a queued plaintext write has no deadline, so a peer that stops reading holds the connection past every sweep) and #224 (the TLS hybrid emit alternates the same two drain cursors). And #226, which is 468 phpt, 444 passed, 0 failed, 0 warned, 24 skipped; |
Closes #219.
The h2c read path ended
http2_feedby draining nghttp2 at the socket withsend(2).http2_session_draintakes the bytes out of the session, so a shortwrite or an EAGAIN discarded them: the response ended mid-frame and the peer
waited for bytes that were not coming. What the socket did accept was written
ahead of the writev the emitter had already handed to the reactor — the overtake
#209 and #211 closed for HTTP/1.
Both halves are reachable from any client that refills its flow-control window
per frame, because each WINDOW_UPDATE wakes the read callback while the response
writev is in flight. Against
main, a 3 MiB body read by a client acking every16 KiB arrives as 2686976 bytes with no END_STREAM.
The read path now calls
http2_session_emit, the same emit the response pathuses: it queues through the connection and skips while a writev is in flight,
because the completion re-drives it. That also removes the second drain API from
this path — the eager loop used
nghttp2_session_mem_sendwhile the emitter usesnghttp2_session_send, and a partially consumedmem_sendslice was strandedwhere the emitter could not reach it.
The two error-path sends go through the queue as well: the bad-preface GOAWAY
template and the GOAWAY nghttp2 queues on a protocol error. The destroy that
follows defers while a write is in flight, so those bytes still leave.
MSG_NOSIGNALhas no call site left and goes with them.Evidence:
tests/phpt/server/h2/057-h2-window-refill-body-intact.phptreads back3 MiB with a distinct byte per chunk and fails against
mainon all three of itslines —
end_stream: no,bytes: 2686976 of 3145728,body: CORRUPT— twice outof two runs. 466 phpt, 442 passed, 0 failed, 0 warned, 24 skipped;
ctest16 of 16.