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 errors in writer loops and omit cancelation after trailers written #149

Merged
merged 2 commits into from
Nov 4, 2024

Conversation

jhump
Copy link
Member

@jhump jhump commented Nov 4, 2024

There was a logic bug in envelopingWriter and transformingWriter that could cause it to spuriously return a non-nil error after it had finished writing trailers for a response.

There was also an issue with responseWriter.reportEnd, which would cancel the operation context, which could then cause the handler to freak out. In particular, httputil.ReverseProxy could observe a context cancelation when trying to proxy the response bytes (even though all response bytes were copied and the cancellation was right after the final byte was written). The reverse proxy, when it encounters an error, will panic(http.ErrAbortWrite), which then causes the HTTP/2 stream to be cancelled (if HTTP/2 is used) instead of a normal stream termination.

This adds the entirety of the repro test case in #148, almost verbatim, to tests in this repo.

Resolves #148.

@jhump jhump requested a review from emcfarlane November 4, 2024 17:10
Signed-off-by: Josh Humphries <[email protected]>
transcoder.go Outdated
@@ -1607,6 +1615,10 @@ func (w *transformingWriter) Write(data []byte) (n int, err error) {
w.rw.reportError(err)
return written, err
}
if w.trailerWritten && len(data) == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can the state flag w.trailerWritten be removed here and changed to:

if w.latestEnvelope.trailer && len(data) == 0 { ... }

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think you're right. Done.

…estEnvelope.trailer flag instead

Signed-off-by: Josh Humphries <[email protected]>
@jhump jhump merged commit c1db73d into main Nov 4, 2024
9 checks passed
@jhump jhump deleted the jh/fix-err-in-writer-loops branch November 4, 2024 18:38
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.

http2 INTERNAL_ERROR when combining vanguard with httputil.ReverseProxy
2 participants