Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: superfluous response.WriteHeader call #724

Closed

Conversation

lidel
Copy link

@lidel lidel commented Mar 11, 2020

This makes WriteHeader do nothing if r.wroteHeader is already true.

It is a more robust way of avoiding superfluous response.WriteHeader call error in the console. Old version fixed redundant calls made by client_golang, this one closes the gap on calls made by third party code, removing error from stdout:

2020/03/11 14:57:06 http: superfluous response.WriteHeader call from github.com/prometheus/client_golang/prometheus/promhttp.(*responseWriterDelegator).WriteHeader (delegator.go:58)

It also makes delegator code simpler and less error prone during refactors.

This makes WriteHeader do nothing if wroteHeader us already true.

It is a more robust way of avoiding superfluous response.WriteHeader
call. Old version fixed redundant calls made by client_golang, this one
closes the gap on calls made by third party code.

It also makes delegator code simpler.

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
Copy link
Contributor

@brian-brazil brian-brazil left a comment

Choose a reason for hiding this comment

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

@@ -53,6 +53,10 @@ func (r *responseWriterDelegator) Written() int64 {
}

func (r *responseWriterDelegator) WriteHeader(code int) {
// Avoid superfluous response.WriteHeader call
Copy link
Contributor

Choose a reason for hiding this comment

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

Full stop

Copy link
Member

@beorn7 beorn7 left a comment

Choose a reason for hiding this comment

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

Great. This way it makes way more sense. Thank you very much.

Could you just address Brian's and my comment nits?

@@ -86,9 +88,7 @@ func (d closeNotifierDelegator) CloseNotify() <-chan bool {
func (d flusherDelegator) Flush() {
// If applicable, call WriteHeader here so that observeWriteHeader is
Copy link
Member

Choose a reason for hiding this comment

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

The "If applicable" is now a bit confusing (as there is no if statement anymore). How about changing this and the other comments to "Call WriteHeader here so that observeWriteHeader is handled appropriately if still needed."

@beorn7
Copy link
Member

beorn7 commented Mar 11, 2020

Thinking about it, perhaps "more robust" is actually not the right way here. I mean, the console message is not a problem on its own. It is there to expose the bug that WriteHeader is called to often. This change will actually mask this error rather than fixing it.

Perhaps we should hear opinions from people experienced with Go HTTP stuff.

@beorn7
Copy link
Member

beorn7 commented Mar 11, 2020

Current state of my thinking process: I tend towards the delegator not changing anything it is not in charge of, i.e. it should not mask/fix superfluous calls of WriteHeader. However, it should be robust against those, so I guess the r.observeWriteHeader(code) should only happen if r.wroteHeader is still false, but the delegation to the original WriteHeader should happen in any case.

@beorn7
Copy link
Member

beorn7 commented Mar 11, 2020

Breaking news: Now we have pretty solid evidence for the root cause, see #672. It's promhttp after all.

@lidel
Copy link
Author

lidel commented Mar 12, 2020

@beorn7 cool, I see you mentioned working on a fix – should we close this PR then?

@beorn7
Copy link
Member

beorn7 commented Mar 12, 2020

Yes, I'll close this now.

I mostly kept it open to remind myself of #724 (comment) . I'll work that into my upcoming fix.

Thanks everyone.

@beorn7 beorn7 closed this Mar 12, 2020
@lidel lidel deleted the fix/superfluous-writeheader-call branch March 13, 2020 16:49
@beorn7 beorn7 mentioned this pull request Mar 13, 2020
takanabe added a commit to takanabe/fastly-exporter that referenced this pull request Jun 10, 2021
prometheus/client_golang v1.0.0 produces superfluous response.WriteHeader call.
Because the unnecessary call was fixed with v1.5.1, updating the version
makes this exporter's logs cleaner.

See prometheus/client_golang#724 for more details.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants