Repository navigation
fix(core): give a queued write a deadline, and the deadline a teardown (#223, #224, #225) - #228
Merged
Merged
Conversation
Contributor
CoverageTotal lines: 82.74% → 82.81% (+0.07 pp)
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #223, #224, #225.
The deadline (#223)
http_write_timer_armhad three callers: the two awaited senders andhttp1_stream.c:335. None of the batched senders armed anything, and everyplaintext HTTP/2 response goes out through them — as does every fire-and-forget
HTTP/1 one since #209 and #211. A peer that stopped reading without closing
wedged the writev:
out_in_flightstayed set,http_connection_destroydeferred on it, and the deadline sweep re-deferred on every tick, so the
connection, its io and its read buffer were never reclaimed.
The deadline is armed at each submit, including the chained ones, so it measures
a write that stopped making progress rather than the lifetime of a whole
response. The arm in
http1_stream.cgoes: the sender under it does it now.Two defects came out of making the timer fire on the common path.
The timer closed the io itself. The reactor frees a handle only when the
close and the dispose come as a pair from one place, and that place is
http_connection_destroy. Arriving second, it found the io already closed, itsown
ZEND_ASYNC_IO_CLOSEbecame a no-op, and the handle stayed in the reactor'stable for good: one 520-byte
async_io_tper timed-out connection, five forfive with five connections. Measured with an external client so no PHP stream of
the test's own is involved. This is not new — on
maina streamed HTTP/1response to a non-reading peer leaks the same handle, because that path arms the
deadline through the awaited sender. A buffered one does not, which is why
arming the batched senders is what made it visible.
The timer now marks the connection, wakes whoever is parked on the outbound
path, and asks for the destroy. The destroy owns the close. For it to run at all
with the write still outstanding, the
out_in_flightdeferral is lifted whenthe deadline has fired — the completion that would lift it is precisely what did
not arrive.
Nothing asked HTTP/2 for a teardown. The stream that timed out ends and the
connection stays, for multiplexing it can no longer do. The h2 stream dispose
also re-checks the deferred destroy after dropping its pin, which its three
sibling sites already did.
The writev completion read the connection before validating it, which the lifted
deferral turns into a use-after-free; it validates first now, and the destroy
fires the writev's user callback itself so the body references are released
while the strategy that owns them is still there.
The last frames (#225)
http2_session_emitskips while a writev is outstanding and leaves the re-driveto the completion — which a path about to destroy the connection will not be
there for.
http2_session_emit_nowruns the same pump and queues behind thatwrite instead. The write completion now asks the session for what it still holds
before finalising a deferred destroy, with
destroy_pendingcleared first so asynchronous submit failure completing from inside the emit cannot destroy under
the frame. A session whose feed answered with a teardown is latched
emit_stopped, so the initial SETTINGS a bad preface leaves queued still do notfollow the GOAWAY out.
One cursor per session (#224)
The TLS hybrid emit picks DRAIN (
mem_send) or GATHER (session_send) per passfrom
large_streams_pending, and DRAIN parks the tail of a slice nghttp2 alreadycounts as sent. GATHER then resumes from the next frame. A parked slice pins the
mode now.
Evidence
tests/phpt/server/h2/060-h2-write-deadline-reclaims.phpt: a peer that stopsreading with
setReadTimeout(30)andsetWriteTimeout(1); the connection gaugedrops within the write deadline, which the read one cannot explain. It guards
the handle leak too — run-tests fails the test on it.
#224 and #225 are carried without tests, and both say why: forcing the TLS mode
to flip with a slice parked needs a fault-injection hook, and #225's window needs
a peer that half-closes with a write in flight.
470 phpt, 446 passed, 0 failed, 0 warned, 24 skipped;
ctest16 of 16. Thebad-preface and protocol-error wires are byte-identical to
main.