-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
transport: fix handling of header metadata in serverHandler #3484
Conversation
ht.rw.Write(hdr) | ||
ht.rw.Write(data) | ||
ht.rw.(http.Flusher).Flush() | ||
}) | ||
} | ||
|
||
func (ht *serverHandlerTransport) WriteHeader(s *Stream, md metadata.MD) error { | ||
if err := s.SetHeader(md); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh I don't really understand why WriteHeader
even takes an md
parameter - IMHO it would be more elegant to implement (*Stream).SendHeader
via
s.SetHeader(md)
s.st.WriteHeader(s)
Since ServerTransport
is an internal interface, I don't see any issues, but it would require changing the http2Server
implementation as well, which is why I opted for a more local change.
CI errors should now be fixed as well. |
Can you explain this a little more? What might be modifying the metadata map and why? I don't believe this should be happening as the metadata godoc says modifying metadata stored in contexts is not allowed (e.g.). |
Actually, nevermind my last question; I see the problem. I think there's a cleaner design here somewhere, but your changes LGTM. |
This was a concurrency error/race condition.
might non-deterministically result in a header with the "foo" key being written or not, since the dispatching of the closure which reads |
This PR changes the
serverHandlerTransport
code to take header metadata from the stream (set via invocations ofSetHeader
) into account, both when implicitly sending headers, or when explicitly sending headers viaSendHeader
(merging any previously set metadata with the additionally supplied one, as per the docs).It also fixes an issue with
SendHeader
where modifications to the passed metadata map after theSendHeader
call has already returned might still affect the header values that get written to the stream.Please check out the first commit in this branch (
3140f261
) for a state that only has the modified test (which of course fails) added.Fixes #3483.