Repository navigation
fix(triple): send buffered streaming writes without waiting for a flush - #3896
Open
AsperforMias wants to merge 1 commit into
Open
AsperforMias wants to merge 1 commit into
AsperforMias wants to merge 1 commit into
Conversation
4 tasks done
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #3896 +/- ##
============================================
+ Coverage 46.76% 61.08% +14.31%
============================================
Files 295 515 +220
Lines 17172 42418 +25246
============================================
+ Hits 8031 25911 +17880
- Misses 8287 14699 +6412
- Partials 854 1808 +954 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
AsperforMias
force-pushed
the
fix/triple-bidi-write-flush
branch
from
November 29, 2026 09:14
8e33bd9 to
32d4f34
Compare
4 tasks done
AsperforMias
force-pushed
the
fix/triple-bidi-write-flush
branch
from
November 29, 2026 09:47
32d4f34 to
8b426f4
Compare
The streaming write buffer held small messages until 32 KiB accumulated, the request side closed, or a receive started waiting. A client stream delivered nothing before CloseAndRecv, a bidi stream that only sent never opened, and a Send made while another goroutine was blocked in Recv never reached the server. With write buffering on, the request body is now a bounded buffered pipe instead of io.Pipe plus a separate buffer. Send copies the message into the 32 KiB buffer and returns; the HTTP transport takes everything buffered on each read. A message sent while the transport is idle goes out at once, and messages sent while it is still writing leave together, so bursts are still batched. A full buffer blocks Send, which keeps flow control in effect. A message at least as large as the buffer is read straight from the caller, as with io.Pipe. CloseWrite after the context has ended now fails the request body and returns the context error, so the server sees the stream reset instead of a request that ended normally.
AsperforMias
force-pushed
the
fix/triple-bidi-write-flush
branch
from
November 29, 2026 10:00
8b426f4 to
3874e2a
Compare
|
This was referenced Nov 29, 2026
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.



Description
Fixes #3893
Part of #3898
The streaming write buffer (32 KiB, on by default since #3749) held small messages until 32 KiB accumulated, the request side closed, or a receive started waiting. As a result:
CloseAndRecv;Sendfrom another goroutine whileRecvwas already blocked never reached the provider ([Bug]: A Triple streaming Send waits in the write buffer until the stream closes or receives #3893).Batching only while an earlier write is still in flight does not help with
io.Pipe: each pipe write returns only after the transport has read it, so a single sender never finds a write in flight, and the buffer would batch nothing. This PR therefore makes the request body itself a bounded buffered pipe when write buffering is on.Changes
bufferedPipereplacesio.PipeplusstreamBufferWriter.Sendcopies the message into a 32 KiB buffer and returns. The HTTP transport reads the request body in its own goroutine and takes everything buffered on each read: a message sent while the transport is idle goes out at once, and messages sent while it is still writing leave together in the next read. A full buffer blocksSend, so flow control still holds senders back. A message at least as large as the buffer is read straight from the caller, as withio.Pipe. Writes are serialized, andCloseRequestwaits for a write in progress, so a message is never cut short.Sendstarts the HTTP request, as it does without buffering.CloseRequestisCloseWriteagain.CloseRequestafter the context has ended fails the request body instead of closing it cleanly and returns the context error, so the provider sees the stream reset rather than a request that ended normally just before the cancellation. With the request now live from the firstSend, the E2E run showed exactly that clean end; the unbufferedio.Pipepath had the same race.The buffer was enabled by default after
v3.3.2-20260910, so the delays affectdeveloponly.Throughput (
tools/benchmark/stream_ab, h2c, local, messages/s, mean of 3 runs of 8 s)With 128 messages of 128 B per stream,
developholds all of a stream's messages untilCloseRequest; this PR sends them as they are written and keeps the batching gain.Verification
TestClientStreamSendReachesPeerBeforeClose,TestBidiSendReachesPeerWithoutReceive,TestWriteBufferingSendsWithoutWaitingForClose: a smallSendreaches the server with nothing closing or waiting.TestBidiSendReachesPeerWhileReceivingkeeps the [Bug]: A Triple streaming Send waits in the write buffer until the stream closes or receives #3893 case. All fail when the pipe hands data to the reader only after close.TestBidiReceiveNotHeldUpBySend: a receive returns while a 16 MiBSendis blocked by flow control.TestDuplexHTTPCallCloseWriteAfterContextEnds: with and without buffering, after cancellation or deadline expiry, closing the request side returns the context error and the transport sees the request body fail instead of end.bufferedPipeunit tests: batching, blocking while full, large writes read directly and in order, no interleaving between concurrent writes, close semantics. Uploading 16 messages of 1 MiB over HTTP/2 runs at the same rate as withio.Pipe(about 3 GB/s locally).TestWriteBufferingDeliversEveryByte: 1000 messages of 100 B arrive in about a dozen server reads.developthe provider receives the three client stream messages together atCloseAndRecvand the bidi messages at the firstRecv; with this PR each arrives within 1 ms of itsSend.Independent of #3897; both touch
duplex_http_call.goin different places.Checklist
developmake fmtto format my codemake testto run local tests