From 21638567eb23733d20af97611adfe7375c67f3bb Mon Sep 17 00:00:00 2001 From: Tim Brooks Date: Mon, 18 Dec 2017 16:07:53 -0600 Subject: [PATCH] Fix issue where pages aren't released This is related to #27422. Right now when we do a write in the netty transport, we attach a listener to the future. When you submit a write on the netty event loop and the event loop is shutdown, the onFailure method is called. Unfortunately, netty then tries to notify the listener which cannot be done without dispatching to the event loop. In this case, the dispatch fails and netty logs and error and does not tell us. This commit checks that netty is still running before sending a message. This will not 100% fix this issue, but it should reduce it. --- .../transport/netty4/Netty4Transport.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java b/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java index 85b49ea022e15..48977762d1e54 100644 --- a/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java +++ b/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java @@ -66,6 +66,7 @@ import org.elasticsearch.transport.ConnectTransportException; import org.elasticsearch.transport.ConnectionProfile; import org.elasticsearch.transport.TcpTransport; +import org.elasticsearch.transport.TransportException; import org.elasticsearch.transport.TransportRequestOptions; import org.elasticsearch.transport.TransportServiceAdapter; import org.elasticsearch.transport.TransportSettings; @@ -393,8 +394,11 @@ protected NodeChannels connectToChannels(DiscoveryNode node, ConnectionProfile p @Override protected void sendMessage(Channel channel, BytesReference reference, ActionListener listener) { - final ChannelFuture future = channel.writeAndFlush(Netty4Utils.toByteBuf(reference)); - future.addListener(f -> { + if (channel.eventLoop().isShuttingDown()) { + listener.onFailure(new TransportException("Cannot send message, event loop is shutting down.")); + } else { + final ChannelFuture future = channel.writeAndFlush(Netty4Utils.toByteBuf(reference)); + future.addListener(f -> { if (f.isSuccess()) { listener.onResponse(channel); } else { @@ -405,7 +409,8 @@ protected void sendMessage(Channel channel, BytesReference reference, ActionList assert cause instanceof Exception; listener.onFailure((Exception) cause); } - }); + }); + } } @Override