Skip to content

Commit

Permalink
netty: Avoid TCP_USER_TIMEOUT warning when not using epoll (#11564)
Browse files Browse the repository at this point in the history
In NettyClientTransport, the TCP_USER_TIMEOUT attribute can be set only
if the channel is of the AbstractEpollStreamChannel.

Fixes #11517
  • Loading branch information
hlx502 authored Oct 22, 2024
1 parent 00c8bc7 commit 62f4098
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions netty/src/main/java/io/grpc/netty/NettyClientTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,6 @@ public Runnable start(Listener transportListener) {
b.channelFactory(channelFactory);
// For non-socket based channel, the option will be ignored.
b.option(SO_KEEPALIVE, true);
// For non-epoll based channel, the option will be ignored.
if (keepAliveTimeNanos != KEEPALIVE_TIME_NANOS_DISABLED) {
ChannelOption<Integer> tcpUserTimeout = Utils.maybeGetTcpUserTimeoutOption();
if (tcpUserTimeout != null) {
b.option(tcpUserTimeout, (int) TimeUnit.NANOSECONDS.toMillis(keepAliveTimeoutNanos));
}
}
for (Map.Entry<ChannelOption<?>, ?> entry : channelOptions.entrySet()) {
// Every entry in the map is obtained from
// NettyChannelBuilder#withOption(ChannelOption<T> option, T value)
Expand Down Expand Up @@ -286,6 +279,20 @@ public void run() {
};
}
channel = regFuture.channel();
// For non-epoll based channel, the option will be ignored.
try {
if (keepAliveTimeNanos != KEEPALIVE_TIME_NANOS_DISABLED
&& Class.forName("io.netty.channel.epoll.AbstractEpollChannel").isInstance(channel)) {
ChannelOption<Integer> tcpUserTimeout = Utils.maybeGetTcpUserTimeoutOption();
if (tcpUserTimeout != null) {
int tcpUserTimeoutMs = (int) TimeUnit.NANOSECONDS.toMillis(keepAliveTimeoutNanos);
channel.config().setOption(tcpUserTimeout, tcpUserTimeoutMs);
}
}
} catch (ClassNotFoundException ignored) {
// JVM did not load AbstractEpollChannel, so the current channel will not be of epoll type,
// so there is no need to set TCP_USER_TIMEOUT
}
// Start the write queue as soon as the channel is constructed
handler.startWriteQueue(channel);
// This write will have no effect, yet it will only complete once the negotiationHandler
Expand Down

0 comments on commit 62f4098

Please sign in to comment.