mirror of https://github.com/grpc/grpc-java.git
netty: Avoid TCP_USER_TIMEOUT warning when not using epoll (#11564)
In NettyClientTransport, the TCP_USER_TIMEOUT attribute can be set only if the channel is of the AbstractEpollStreamChannel. Fixes #11517
This commit is contained in:
parent
00c8bc78dd
commit
62f409810d
|
|
@ -241,13 +241,6 @@ class NettyClientTransport implements ConnectionClientTransport {
|
||||||
b.channelFactory(channelFactory);
|
b.channelFactory(channelFactory);
|
||||||
// For non-socket based channel, the option will be ignored.
|
// For non-socket based channel, the option will be ignored.
|
||||||
b.option(SO_KEEPALIVE, true);
|
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()) {
|
for (Map.Entry<ChannelOption<?>, ?> entry : channelOptions.entrySet()) {
|
||||||
// Every entry in the map is obtained from
|
// Every entry in the map is obtained from
|
||||||
// NettyChannelBuilder#withOption(ChannelOption<T> option, T value)
|
// NettyChannelBuilder#withOption(ChannelOption<T> option, T value)
|
||||||
|
|
@ -286,6 +279,20 @@ class NettyClientTransport implements ConnectionClientTransport {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
channel = regFuture.channel();
|
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
|
// Start the write queue as soon as the channel is constructed
|
||||||
handler.startWriteQueue(channel);
|
handler.startWriteQueue(channel);
|
||||||
// This write will have no effect, yet it will only complete once the negotiationHandler
|
// This write will have no effect, yet it will only complete once the negotiationHandler
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue