cockroachdb / cockroachdb/cockroach
drpcwire: reader buffer never shrinks
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
Reader.buf in drpcwire/reader.go grows to accommodate large frames but never shrinks back. Once a single large message inflates the buffer (e.g. to several MB), that memory stays allocated for the lifetime of the connection, even if all subsequent messages are small.
The growth logic at reader.go:110-115 doubles capacity plus 4096 bytes each time free space drops below 4096. After a successful packet parse, the buffer length resets to zero reader.go:138, but the underlying array and its capacity are retained.
On long-lived connections that occasionally receive large messages, this leads to memory that is allocated but effectively unused.
One option is to check the capacity after a successful read and, if it exceeds some threshold relative to recent usage, replace r.buf with a smaller allocation.
Jira issue: CRDB-62097
Contributor guide
Assessment
This issue has not been assessed yet.