Skip to content

Commit

Permalink
transport: don't check s.header on the server side in Stream.Header (#…
Browse files Browse the repository at this point in the history
…3063)

Previously this would fall into returning the same "s.header.Copy(), nil"
condition at the end of the function, returning an empty MD.  After a recent
change it would instead check headerValid, which is always false on servers,
and return nil and an error.  Callers were ignoring this error so no behavior
change was seen, but there is no need to check s.headers here.
  • Loading branch information
dfawley committed Oct 2, 2019
1 parent 5df282e commit 2e14ef2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/transport/http2_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ func (t *http2Server) checkForHeaderListSize(it interface{}) bool {
return true
}

// WriteHeader sends the header metedata md back to the client.
// WriteHeader sends the header metadata md back to the client.
func (t *http2Server) WriteHeader(s *Stream, md metadata.MD) error {
if s.updateHeaderSent() || s.getState() == streamDone {
return ErrIllegalHeaderWrite
Expand Down
7 changes: 4 additions & 3 deletions internal/transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ type Stream struct {
headerChanClosed uint32 // set when headerChan is closed. Used to avoid closing headerChan multiple times.
// headerValid indicates whether a valid header was received. Only
// meaningful after headerChan is closed (always call waitOnHeader() before
// reading its value).
// reading its value). Not valid on server side.
headerValid bool

// hdrMu protects header and trailer metadata on the server-side.
Expand Down Expand Up @@ -351,9 +351,10 @@ func (s *Stream) Done() <-chan struct{} {
// available. It blocks until i) the metadata is ready or ii) there is no header
// metadata or iii) the stream is canceled/expired.
//
// On server side, it returns the out header after t.WriteHeader is called.
// On server side, it returns the out header after t.WriteHeader is called. It
// does not block and must not be called until after WriteHeader.
func (s *Stream) Header() (metadata.MD, error) {
if s.headerChan == nil && s.header != nil {
if s.headerChan == nil {
// On server side, return the header in stream. It will be the out
// header after t.WriteHeader is called.
return s.header.Copy(), nil
Expand Down

0 comments on commit 2e14ef2

Please sign in to comment.