netty: Populate Channelz TcpInfo from netty-epoll by JoeCqupt · Pull Request #13135 · grpc/grpc-java · GitHub
Skip to content

netty: Populate Channelz TcpInfo from netty-epoll - #13135

Open
JoeCqupt wants to merge 1 commit into
grpc:masterfrom
JoeCqupt:feat/netty-epoll-tcpinfo
Open

JoeCqupt wants to merge 1 commit into
grpc:masterfrom
JoeCqupt:feat/netty-epoll-tcpinfo

Conversation

@JoeCqupt

Copy link
Copy Markdown
Contributor

The default NettySocketSupport helper has always returned null (see the
TODO(zpencer) in NettySocketHelperImpl), so Channelz never reported
TCP_INFO for open-source users. When netty-epoll is available, this reads
EpollSocketChannel.tcpInfo() via reflection and maps all fields into
InternalChannelz.TcpInfo. grpc-netty does not depend on netty-epoll at
compile time, so reflection is still required. Helpers injected through
InternalNettySocketSupport.setHelper are unaffected.

TcpMetrics already had similar epoll reflection (TcpMetrics.EpollInfo), so
it is extracted into a package-private EpollTcpInfoAccessor shared by both
callers. All getters are resolved once at class init; if any is missing, epoll
support is disabled as a whole, as before.

Fix: grpc.tcp.recurring_retransmits read the wrong field

While doing this, I noticed that TcpMetrics populated
grpc.tcp.recurring_retransmits from EpollTcpInfo.retrans()
(tcpi_retrans, the number of currently unacknowledged retransmitted
segments). The metric is defined as "the total number of times the retransmit
timer popped" (unit {timeout}), which corresponds to
EpollTcpInfo.retransmits() (tcpi_retransmits). This PR fixes it to read
retransmits(), so reported values for this metric will change.

Testing

  • NettySocketSupportTest: all 29 fields mapped with distinct values; returns
    null for non-epoll channels, when epoll is unavailable, and when reading
    fails (e.g. closed fd); plus a loopback test on a real EpollSocketChannel
    (Linux only, skipped elsewhere) asserting state == ESTABLISHED.
  • EpollTcpInfoAccessorTest: verifies every getter name resolves against the
    real netty EpollSocketChannel / EpollTcpInfo classes (no native load
    needed, runs on any platform).
  • TcpMetricsTest: migrated to the shared fake; new regression test
    tracker_recurringRetransmits_usesRetransmitsNotRetrans.

The default NettySocketSupport helper always returned null, so Channelz
never reported TCP_INFO for open-source users. When netty-epoll is
available, read EpollSocketChannel.tcpInfo() via reflection and map all
fields into InternalChannelz.TcpInfo.

The epoll reflection previously private to TcpMetrics is extracted into
EpollTcpInfoAccessor and shared by both callers.

Also fix grpc.tcp.recurring_retransmits, which was reading tcpi_retrans
(currently unacknowledged retransmitted segments) instead of
tcpi_retransmits (number of retransmission timer expirations), which is
what the metric is defined to count.
@JoeCqupt

JoeCqupt commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant