Skip to content

Conversation

@krissetto
Copy link
Contributor

@krissetto krissetto commented Apr 15, 2024

What I did

  • Deprecated and moved writeflusher impl to internal pkg (since it was exported and a few external projects seem to use it)
  • Added new internal writeflusher implementation, removing some old buggy bits and adjusting the Flush() func to also call WriteHeader() on the underlying io.Writer if it's an http.ResponseWriter.
    This is needed to ensure that we don't try to send headers multiple times if the writer has already been wrapped by OTEL instrumentation (which doesn't wrap the Flush() func. See Syslog entry: "superfluous response.WriteHeader call" in Docker 25.x #47448)

How I did it
I moved the old impl to internal/writeflusher, and created a NewLegacyWriteFlusher() func that the old exported NewWriteFlusher() func calls to maintain the original behavior. All code using this deprecated version from the ioutils pkg should be unaffected

How to verify it
Usual tests should run as usual, as this shouldn't have any effect

Description for the changelog

Create new internal implementation for writeflusher and deprecate the old one

A picture of a cute animal (not mandatory but encouraged)
image

@krissetto krissetto force-pushed the writeflusher-internal-impl branch 2 times, most recently from 0ad6eb4 to e76e088 Compare April 15, 2024 13:13
@krissetto krissetto force-pushed the writeflusher-internal-impl branch from e76e088 to b4ebe28 Compare April 17, 2024 10:48
@krissetto krissetto marked this pull request as ready for review April 17, 2024 10:49
@laurazard laurazard added status/2-code-review kind/refactor PR's that refactor, or clean-up code labels Apr 17, 2024
…Flusher

Signed-off-by: Christopher Petito <47751006+krissetto@users.noreply.github.com>
…riteHeader() on first Flush())

Signed-off-by: Christopher Petito <47751006+krissetto@users.noreply.github.com>
@krissetto krissetto force-pushed the writeflusher-internal-impl branch from b4ebe28 to d020e95 Compare April 18, 2024 13:57
// NewLegacyWriteFlusher returns a new LegacyWriteFlusher.
//
// Deprecated: use the internal writeflusher.NewWriteFlusher() instead
func NewLegacyWriteFlusher(w io.Writer) *LegacyWriteFlusher {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is still used in a bunch of places in API, which makes the linter complain:

api/server/router/build/build_routes.go:234:12: SA1019: ioutils.NewWriteFlusher is deprecated: use the internal/writeflusher WriteFlusher instead. (staticcheck)
	output := ioutils.NewWriteFlusher(ww)
...

we should also replace these with the new implementation.


// NewLegacyWriteFlusher returns a new LegacyWriteFlusher.
//
// Deprecated: use the internal writeflusher.NewWriteFlusher() instead
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to add the deprecation and removal notice to https://github.com/docker/cli/blob/master/docs/deprecated.md? @thaJeztah

While not strictly an API, if we're bothering with the deprecation-cycle anyway, perhaps it wouldn't hurt to call it out in our docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR was created as a solution to the "superfluous call to writeheader" issue. It seemed like a good moment to go ahead and deprecate the old writeflusher implementation which was exposing some known buggy functionality (

func (wf *WriteFlusher) Flushed() bool {
// BUG(stevvooe): Remove this method. Its use is inherently racy. Seems to
// be used to detect whether or a response code has been issued or not.
// Another hook should be used instead.
var flushed bool
select {
case <-wf.flushed:
flushed = true
default:
}
return flushed
)

If we merge #47796, this PR will no longer be necessary unless we still want to deprecate the old writeflusher implementation

@vvoland vvoland added this to the 27.0.0 milestone May 14, 2024
@vvoland vvoland modified the milestones: 27.0.0, v-future Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor PR's that refactor, or clean-up code status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants