Skip to content

Commit

Permalink
In NettyClientTransport, the TCP_USER_TIMEOUT attribute can be set on…
Browse files Browse the repository at this point in the history
…ly if the channel is of the AbstractEpollStreamChannel.
  • Loading branch information
hlx502 committed Oct 10, 2024
1 parent ce8b708 commit cfa025d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 0 additions & 1 deletion netty/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ dependencies {
libraries.netty.codec.http2
implementation project(':grpc-core'),
libs.netty.handler.proxy,
libs.netty.transport.epoll,
libraries.guava,
libraries.errorprone.annotations,
libraries.perfmark.api,
Expand Down
14 changes: 9 additions & 5 deletions netty/src/main/java/io/grpc/netty/NettyClientTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.epoll.AbstractEpollStreamChannel;
import io.netty.handler.codec.http2.StreamBufferingEncoder.Http2ChannelClosedException;
import io.netty.util.AsciiString;
import io.netty.util.concurrent.Future;
Expand Down Expand Up @@ -281,11 +280,16 @@ public void run() {
}
channel = regFuture.channel();
// For non-epoll based channel, the option will be ignored.
if (keepAliveTimeNanos != KEEPALIVE_TIME_NANOS_DISABLED && channel instanceof AbstractEpollStreamChannel) {
ChannelOption<Integer> tcpUserTimeout = Utils.maybeGetTcpUserTimeoutOption();
if (tcpUserTimeout != null) {
channel.config().setOption(tcpUserTimeout, (int) TimeUnit.NANOSECONDS.toMillis(keepAliveTimeoutNanos));
try {
boolean isEpollChannel = Class.forName("io.netty.channel.epoll.AbstractEpollChannel").isInstance(channel);
if (keepAliveTimeNanos != KEEPALIVE_TIME_NANOS_DISABLED && isEpollChannel) {
ChannelOption<Integer> tcpUserTimeout = Utils.maybeGetTcpUserTimeoutOption();
if (tcpUserTimeout != null) {
channel.config().setOption(tcpUserTimeout, (int) TimeUnit.NANOSECONDS.toMillis(keepAliveTimeoutNanos));
}
}
} catch (ClassNotFoundException ignored) {

}
// Start the write queue as soon as the channel is constructed
handler.startWriteQueue(channel);
Expand Down

0 comments on commit cfa025d

Please sign in to comment.