Skip to content

Commit

Permalink
transport: Fix reporting of bytes read while reading headers (#7660) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
arjan-bal authored Sep 24, 2024
1 parent 02bbb65 commit 935f8cb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,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)
}
}

0 comments on commit 935f8cb

Please sign in to comment.