Fix errors in writer loops and omit cancelation after trailers written #149
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.
There was a logic bug in
envelopingWriter
andtransformingWriter
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, willpanic(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.