-
Notifications
You must be signed in to change notification settings - Fork 25.6k
transport: pass network channel exceptions to close listeners #127895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
7498303
3ffdba7
86342af
d820810
326c2a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,7 +54,6 @@ | |
| import java.util.Map; | ||
|
|
||
| import static org.elasticsearch.common.util.concurrent.ConcurrentCollections.newConcurrentMap; | ||
| import static org.elasticsearch.core.Strings.format; | ||
| import static org.elasticsearch.transport.RemoteClusterPortSettings.REMOTE_CLUSTER_PROFILE; | ||
| import static org.elasticsearch.transport.RemoteClusterPortSettings.REMOTE_CLUSTER_SERVER_ENABLED; | ||
|
|
||
|
|
@@ -308,18 +307,27 @@ protected void stopInternal() { | |
| }, serverBootstraps::clear, () -> clientBootstrap = null); | ||
| } | ||
|
|
||
| private Exception exceptionFromThrowable(Throwable cause) { | ||
|
||
| if (cause instanceof Error) { | ||
| return new Exception(cause); | ||
| } else { | ||
| return (Exception) cause; | ||
| } | ||
| } | ||
|
|
||
| protected class ClientChannelInitializer extends ChannelInitializer<Channel> { | ||
|
|
||
| @Override | ||
| protected void initChannel(Channel ch) throws Exception { | ||
| addClosedExceptionLogger(ch); | ||
| assert ch instanceof Netty4NioSocketChannel; | ||
| NetUtils.tryEnsureReasonableKeepAliveConfig(((Netty4NioSocketChannel) ch).javaChannel()); | ||
| setupPipeline(ch, false); | ||
| } | ||
|
|
||
| @Override | ||
| public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { | ||
| Netty4TcpChannel channel = ctx.channel().attr(CHANNEL_KEY).get(); | ||
| channel.setCloseException(exceptionFromThrowable(cause)); | ||
| ExceptionsHelper.maybeDieOnAnotherThread(cause); | ||
| super.exceptionCaught(ctx, cause); | ||
| } | ||
|
|
@@ -337,7 +345,6 @@ protected ServerChannelInitializer(String name) { | |
|
|
||
| @Override | ||
| protected void initChannel(Channel ch) throws Exception { | ||
| addClosedExceptionLogger(ch); | ||
| assert ch instanceof Netty4NioSocketChannel; | ||
| NetUtils.tryEnsureReasonableKeepAliveConfig(((Netty4NioSocketChannel) ch).javaChannel()); | ||
| Netty4TcpChannel nettyTcpChannel = new Netty4TcpChannel(ch, true, name, rstOnClose, ch.newSucceededFuture()); | ||
|
|
@@ -348,6 +355,8 @@ protected void initChannel(Channel ch) throws Exception { | |
|
|
||
| @Override | ||
| public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { | ||
| Netty4TcpChannel channel = ctx.channel().attr(CHANNEL_KEY).get(); | ||
| channel.setCloseException(exceptionFromThrowable(cause)); | ||
| ExceptionsHelper.maybeDieOnAnotherThread(cause); | ||
| super.exceptionCaught(ctx, cause); | ||
| } | ||
|
|
@@ -383,14 +392,6 @@ protected InboundPipeline getInboundPipeline(Channel ch, boolean isRemoteCluster | |
| ); | ||
| } | ||
|
|
||
| private static void addClosedExceptionLogger(Channel channel) { | ||
| Netty4Utils.addListener(channel.closeFuture(), channelFuture -> { | ||
| if (channelFuture.isSuccess() == false && logger.isDebugEnabled()) { | ||
| logger.debug(format("exception while closing channel: %s", channelFuture.channel()), channelFuture.cause()); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| @ChannelHandler.Sharable | ||
| private static class ServerChannelExceptionHandler extends ChannelInboundHandlerAdapter { | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.