connectrpc / vanguard-go

Support REST, gRPC, gRPC-Web, and Connect clients with one server.
https://pkg.go.dev/connectrpc.com/vanguard
Apache License 2.0
236 stars 14 forks source link

Fix errors in writer loops and omit cancelation after trailers written #149

Closed jhump closed 4 weeks ago

jhump commented 4 weeks ago

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.