fix(http): get-stream yields lines on newline, not buffer-fill (ILO-489)#779
Merged
Conversation
ac2783c to
fcb06ec
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
replace the BufReader::lines() wrapper around minreq's ResponseLazy with a LazyLineSplitter that consumes the byte iterator incrementally and emits each line the instant its newline arrives. the BufReader path blocked on a full read-buffer fill before surfacing any line, so a slow SSE upstream had its events batched until the buffer filled or the connection closed. trailing \r stripped for chunked/CRLF encoding, EOF yields any partial line, mid-stream errors still surface as io errors.
add a slow-drip server that flushes one line, idles 300ms, then sends a second, reporting the instant line 2 hits the wire. assert the client surfaces line 1 before that instant - this fails on the old buffered code (line 1 batched until line 2 arrives) and passes on the fix. also cover a trailing newline-less line yielded at EOF.
fcb06ec to
ee36fad
Compare
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.
Summary
get-stream/pst-stream(ILO-448) yield lines lazily, but the native backend wrapped minreq'sResponseLazyinBufReader::lines(), which blocks on a full ~8 KiB read-buffer fill before surfacing any line. So a slow SSE upstream that flushes one short event then idles had its lines batched until the buffer filled or the connection closed. Functionally correct (all lines arrive in order) but latency was buffer-bound, not event-bound.Motivation: this directly unblocks ILO-482's end-to-end test, which proxies an upstream via
get-streamto prove httpd lazy-body streaming and was flaky (~1 in 3) because get-stream sometimes hadn't yielded the first line when the test read. Per-newline yield makes that test deterministic.Repro before/after
A server flushes
first\n, idles 300ms, then sendssecond\nwithout closing.firstuntilsecond(or close) arrives - line 1 lands ~200us after line 2 hits the wire (batched).firstthe instant its\narrives, well before line 2 is sent.What changed (per commit)
fix(http): stream get-stream lines on newline, not buffer-fill- replace theBufReader::lines()wrapper with aLazyLineSplitterthat consumesResponseLazy's byte iterator incrementally, emitting each line the moment a\nis seen. Strips a trailing\rfor chunked/CRLF, yields any partial line at EOF, mapsminreq::Error::IoErrorback to theio::Errorthe existingILO-R009 http-stream read errorpath expects. Covers all four builtins (get-stream, get-stream-h, pst-stream, pst-stream-h).test(http): prove get-stream yields per-newline, not per-buffer- slow-drip server reports the instant line 2 hits the wire; the test asserts line 1 arrived before then with margin. Verified to fail on the old buffered code and pass on the fix. Plus a trailing newline-less EOF line test.docs: note get-stream per-newline yield (ILO-489)- CHANGELOG Unreleased entry + skill doc latency note.Test plan
cargo fmtcargo clippy --release --all-targets --features cranelift -- -D warningscleancargo test --release --features craneliftgreen (406 lib + all integration; only the two tolerated baseline doctests insrc/pkg.rs/src/verify.rsfail, as on main)Follow-ups
None.