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
net/http: undeclared HTTP/2 trailers not sent when response body is empty and unflushed #54723
Comments
cc @neild |
Change https://go.dev/cl/426157 mentions this issue: |
i send a wip cl. i found |
@ianwoolf Any changes to the code in |
sorry i missed that, i am sending a new cl to |
Change https://go.dev/cl/426754 mentions this issue: |
Change https://go.dev/cl/426874 mentions this issue: |
The problem is that we're checking for undeclared trailers (with the magic You can probably also work around the problem by calling https://go.dev/cl/426874 contains a fix. |
hmm.. i get it, thank you |
Thanks for the fix, @neild! The bit of code I was looking at can predeclare trailers, so I just set the |
Fix a bug wherein undeclared trailers (set with the "Trailer:" prefix) were not sent when the response body is neither written nor flushed. We were testing responseWriterState.hasTrailers before promoting undeclared trailers into rws.trailers, resulting in the response headers being sent with an END_STREAM flag. Promote undeclared headers earlier so that we leave the stream open for them to be sent. For golang/go#54723 Change-Id: Ic036925f4a7ec775282b6e474aa72249d6418b23 Reviewed-on: https://go-review.googlesource.com/c/net/+/426874 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
Fix a bug wherein undeclared trailers (set with the "Trailer:" prefix) were not sent when the response body is neither written nor flushed. We were testing responseWriterState.hasTrailers before promoting undeclared trailers into rws.trailers, resulting in the response headers being sent with an END_STREAM flag. Promote undeclared headers earlier so that we leave the stream open for them to be sent. For golang/go#54723 Change-Id: Ic036925f4a7ec775282b6e474aa72249d6418b23 Reviewed-on: https://go-review.googlesource.com/c/net/+/426874 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
In a
net/http
handler, I wrote some HTTP trailers to the response writer usinghttp.TrailerPrefix
. The handler never writes to or flushes the response body. (This is admittedly odd, but trailers without a body are necessary in the gRPC HTTP/2 protocol.)What did you expect to see?
I expected the client to receive the trailers regardless of the HTTP protocol version in use.
What did you see instead?
Everything works as expected when the server and client use HTTP/1.1. Regardless of the HTTP protocol version, everything also works as expected if I stop using
http.TrailerPrefix
and instead set the "Trailer" header.When the client negotiates up to HTTP/2 and the handler uses
http.TrailerPrefix
, the client doesn't receive any trailers unless the handler flushes the response body. This is a little strange - it doesn't match the HTTP/1.x behavior, and it's not obvious why flushing a response without any buffered data should do anything at all. (I assume that something in x/net/http2 doesn't send trailers unless we've sent a DATA frame, and perhaps flushing always sends a frame? I haven't dug far enough to verify that hypothesis.)Here's a reproduction:
The text was updated successfully, but these errors were encountered: