Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

cherry-pick #7660 to v1.66.x branch #7668

Merged
merged 1 commit into from
Sep 25, 2024
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 @@ -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)
}
}
Loading