Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ func (t *transportReader) ReadHeader(header []byte) (int, error) {
t.er = err
return 0, err
}
t.windowHandler(len(header))
t.windowHandler(n)
return n, nil
}

Expand Down
31 changes: 31 additions & 0 deletions internal/transport/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2845,3 +2845,34 @@ func (s) TestClientCloseReturnsEarlyWhenGoAwayWriteHangs(t *testing.T) {
isGreetingDone.Store(true)
ct.Close(errors.New("manually closed by client"))
}

// TestReadHeaderMultipleBuffers tests the stream when the gRPC headers are
// split across multiple buffers. It verifies that the reporting of the
// number of bytes read for flow control is correct.
func (s) TestReadHeaderMultipleBuffers(t *testing.T) {
headerLen := 5
recvBuffer := newRecvBuffer()
recvBuffer.put(recvMsg{buffer: make(mem.SliceBuffer, 3)})
recvBuffer.put(recvMsg{buffer: make(mem.SliceBuffer, headerLen-3)})
bytesRead := 0
s := Stream{
requestRead: func(int) {},
trReader: &transportReader{
reader: &recvBufferReader{
recv: recvBuffer,
},
windowHandler: func(i int) {
bytesRead += i
},
},
}

header := make([]byte, headerLen)
err := s.ReadHeader(header)
if err != nil {
t.Fatalf("ReadHeader(%v) = %v", header, err)
}
if bytesRead != headerLen {
t.Errorf("bytesRead = %d, want = %d", bytesRead, headerLen)
}
}