diff --git a/src/main/java/org/elasticsearch/transport/TransportService.java b/src/main/java/org/elasticsearch/transport/TransportService.java index 410118b1771..a2ba7e45e1e 100644 --- a/src/main/java/org/elasticsearch/transport/TransportService.java +++ b/src/main/java/org/elasticsearch/transport/TransportService.java @@ -182,7 +182,7 @@ public class TransportService extends AbstractLifecycleComponent(handler, node, action, timeoutHandler)); transport.sendRequest(node, requestId, action, request, options); - } catch (final Exception e) { + } catch (final Throwable e) { // usually happen either because we failed to connect to the node // or because we failed serializing the message clientHandlers.remove(requestId); diff --git a/src/main/java/org/elasticsearch/transport/local/LocalTransport.java b/src/main/java/org/elasticsearch/transport/local/LocalTransport.java index f150d587d9b..c413b89908f 100644 --- a/src/main/java/org/elasticsearch/transport/local/LocalTransport.java +++ b/src/main/java/org/elasticsearch/transport/local/LocalTransport.java @@ -208,11 +208,11 @@ public class LocalTransport extends AbstractLifecycleComponent implem } } } - } catch (Exception e) { + } catch (Throwable e) { if (sendRequestId != null) { TransportResponseHandler handler = transportServiceAdapter.remove(sendRequestId); if (handler != null) { - handler.handleException(new RemoteTransportException(nodeName(), localAddress, action, e)); + handleException(handler, new RemoteTransportException(nodeName(), localAddress, action, e)); } } else { logger.warn("Failed to receive message for action [" + action + "]", e); @@ -246,7 +246,7 @@ public class LocalTransport extends AbstractLifecycleComponent implem final TransportResponse response = handler.newInstance(); try { response.readFrom(buffer); - } catch (Exception e) { + } catch (Throwable e) { handleException(handler, new TransportSerializationException("Failed to deserialize response of type [" + response.getClass().getName() + "]", e)); return; } @@ -256,7 +256,7 @@ public class LocalTransport extends AbstractLifecycleComponent implem public void run() { try { handler.handleResponse(response); - } catch (Exception e) { + } catch (Throwable e) { handleException(handler, new ResponseHandlerFailureTransportException(e)); } } @@ -279,6 +279,10 @@ public class LocalTransport extends AbstractLifecycleComponent implem error = new RemoteTransportException("None remote transport exception", error); } final RemoteTransportException rtx = (RemoteTransportException) error; - handler.handleException(rtx); + try { + handler.handleException(rtx); + } catch (Throwable t) { + logger.error("failed to handle exception response [{}]", t, handler); + } } } diff --git a/src/main/java/org/elasticsearch/transport/netty/MessageChannelHandler.java b/src/main/java/org/elasticsearch/transport/netty/MessageChannelHandler.java index 55f85b1f187..a3b9bc0a068 100644 --- a/src/main/java/org/elasticsearch/transport/netty/MessageChannelHandler.java +++ b/src/main/java/org/elasticsearch/transport/netty/MessageChannelHandler.java @@ -143,7 +143,7 @@ public class MessageChannelHandler extends SimpleChannelUpstreamHandler { final TransportResponse response = handler.newInstance(); try { response.readFrom(buffer); - } catch (Exception e) { + } catch (Throwable e) { handleException(handler, new TransportSerializationException("Failed to deserialize response of type [" + response.getClass().getName() + "]", e)); return; } @@ -176,7 +176,11 @@ public class MessageChannelHandler extends SimpleChannelUpstreamHandler { } final RemoteTransportException rtx = (RemoteTransportException) error; if (handler.executor() == ThreadPool.Names.SAME) { - handler.handleException(rtx); + try { + handler.handleException(rtx); + } catch (Throwable e) { + logger.error("failed to handle exception response [{}]", e, handler); + } } else { threadPool.executor(handler.executor()).execute(new Runnable() { @Override @@ -184,7 +188,7 @@ public class MessageChannelHandler extends SimpleChannelUpstreamHandler { try { handler.handleException(rtx); } catch (Throwable e) { - logger.error("Failed to handle exception response", e); + logger.error("failed to handle exception response [{}]", e, handler); } } });