Skip to content

server/router/build: replace output buffering workaround with EnableFullDuplex - #52364

Merged
thaJeztah merged 1 commit into
moby:masterfrom
VedantMadane:build-remove-output-buffering-workaround
May 7, 2026
Merged

server/router/build: replace output buffering workaround with EnableFullDuplex#52364
thaJeztah merged 1 commit into
moby:masterfrom
VedantMadane:build-remove-output-buffering-workaround

Conversation

@VedantMadane

Copy link
Copy Markdown
Contributor

The wrapOutputBufferedUntilRequestRead helper and its support types (wcf, rcNotifier, flusher, nopFlusher) were introduced in #37151 to work around Go not supporting full-duplex HTTP/1 responses (golang/go#15527, golang/go#22209). Without the workaround, writing the build progress stream before the request body (the build context tar) was fully consumed could corrupt the connection.

Since Go 1.21 (https://go.dev/cl/472636, https://go.dev/cl/501300), the standard library ships http.ResponseController.EnableFullDuplex which is exactly the recommended replacement. Moby already requires Go 1.25, so we can rely on it unconditionally.

This PR replaces the entire buffering machinery with a single EnableFullDuplex call at the top of postBuild, then passes r.Body and w through directly. The bufio import is removed as it was only used by the workaround.

Fixes #51209

@github-actions github-actions Bot added the area/daemon Core Engine label Apr 15, 2026
@VedantMadane
VedantMadane force-pushed the build-remove-output-buffering-workaround branch from 639cdd0 to 4952040 Compare April 15, 2026 14:54
@vvoland vvoland added this to the 29.5.0 milestone Apr 16, 2026

@vvoland vvoland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good!


body := r.Body
var ww io.Writer = w
if body != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep the r.Body != nil check?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it may be redundant for server requests; https://pkg.go.dev/net/http#Request.Body

	// For client requests, a nil body means the request has no
	// body, such as a GET request. The HTTP Client's Transport
	// is responsible for calling the Close method.
	//
	// For server requests, the Request Body is always non-nil
	// but will return EOF immediately when no body is present.
	// The Server will close the request body. The ServeHTTP
	// Handler does not need to.

Comment thread daemon/server/router/build/build_routes.go Outdated
…ullDuplex

The wrapOutputBufferedUntilRequestRead helper was added as a workaround
for Go not supporting full-duplex HTTP/1 responses (golang/go#15527,
golang/go#22209). Since Go 1.21, the standard library ships
http.ResponseController.EnableFullDuplex which tells the server that
the handler will interleave reads and writes, making the buffering
wrap unnecessary.

Replace the workaround with a single EnableFullDuplex call and remove
the helper types (wcf, rcNotifier, flusher, nopFlusher) that were only
used by the old path.

Fixes moby#51209

Signed-off-by: Vedant Madane <vedant.madane@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah
thaJeztah force-pushed the build-remove-output-buffering-workaround branch from 4952040 to 70ac493 Compare May 6, 2026 23:35
@thaJeztah

Copy link
Copy Markdown
Member

Did a quick rebase and fixed the linting issue

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@thaJeztah
thaJeztah merged commit 41eecbf into moby:master May 7, 2026
246 of 251 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

server/router/build: remove wrapOutputBufferedUntilRequestRead workaround if possible

3 participants