Java Code Examples for org.jboss.netty.channel.ExceptionEvent#getCause()

The following examples show how to use org.jboss.netty.channel.ExceptionEvent#getCause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShuffleHandler.java    From RDFS with Apache License 2.0 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
    throws Exception {
  Channel ch = e.getChannel();
  Throwable cause = e.getCause();
  if (cause instanceof TooLongFrameException) {
    sendError(ctx, BAD_REQUEST);
    return;
  }

  LOG.error("Shuffle error: ", cause);
  shuffleMetrics.failedOutput();
  if (ch.isConnected()) {
    LOG.error("Shuffle error " + e);
    sendError(ctx, INTERNAL_SERVER_ERROR);
  }
}
 
Example 2
Source File: ShuffleHandler.java    From tez with Apache License 2.0 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
    throws Exception {
  Channel ch = e.getChannel();
  Throwable cause = e.getCause();
  if (cause instanceof TooLongFrameException) {
    sendError(ctx, BAD_REQUEST);
    return;
  } else if (cause instanceof IOException) {
    if (cause instanceof ClosedChannelException) {
      LOG.debug("Ignoring closed channel error", cause);
      return;
    }
    String message = String.valueOf(cause.getMessage());
    if (IGNORABLE_ERROR_MESSAGE.matcher(message).matches()) {
      LOG.debug("Ignoring client socket close", cause);
      return;
    }
  }

  LOG.error("Shuffle error: ", cause);
  if (ch.isConnected()) {
    LOG.error("Shuffle error " + e);
    sendError(ctx, INTERNAL_SERVER_ERROR);
  }
}
 
Example 3
Source File: ShuffleHandler.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
    throws Exception {
  Channel ch = e.getChannel();
  Throwable cause = e.getCause();
  if (cause instanceof TooLongFrameException) {
    sendError(ctx, BAD_REQUEST);
    return;
  } else if (cause instanceof IOException) {
    if (cause instanceof ClosedChannelException) {
      LOG.debug("Ignoring closed channel error", cause);
      return;
    }
    String message = String.valueOf(cause.getMessage());
    if (IGNORABLE_ERROR_MESSAGE.matcher(message).matches()) {
      LOG.debug("Ignoring client socket close", cause);
      return;
    }
  }

  LOG.error("Shuffle error: ", cause);
  if (ch.isConnected()) {
    LOG.error("Shuffle error " + e);
    sendError(ctx, INTERNAL_SERVER_ERROR);
  }
}
 
Example 4
Source File: NettyAsyncHttpProvider.java    From ck with Apache License 2.0 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
		throws Exception {
	Channel ch = e.getChannel();
	Throwable cause = e.getCause();

	if (log.isDebugEnabled())
		log.debug("I/O Exception during read or doConnect: ", cause);
	if (ctx.getAttachment() instanceof NettyResponseFuture<?>) {
		NettyResponseFuture<?> future = (NettyResponseFuture<?>) ctx.getAttachment();

		if (future!= null){
			future.getAsyncHandler().onThrowable(cause);
		}
	}

	if (log.isDebugEnabled()){
		log.debug(e);
		log.debug(ch);
	}
}
 
Example 5
Source File: ShuffleHandler.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
    throws Exception {
  Channel ch = e.getChannel();
  Throwable cause = e.getCause();
  if (cause instanceof TooLongFrameException) {
    sendError(ctx, BAD_REQUEST);
    return;
  } else if (cause instanceof IOException) {
    if (cause instanceof ClosedChannelException) {
      LOG.debug("Ignoring closed channel error", cause);
      return;
    }
    String message = String.valueOf(cause.getMessage());
    if (IGNORABLE_ERROR_MESSAGE.matcher(message).matches()) {
      LOG.debug("Ignoring client socket close", cause);
      return;
    }
  }

  LOG.error("Shuffle error: ", cause);
  if (ch.isConnected()) {
    LOG.error("Shuffle error " + e);
    sendError(ctx, INTERNAL_SERVER_ERROR);
  }
}
 
Example 6
Source File: ClientIOHandler.java    From nfs-client-java with Apache License 2.0 6 votes vote down vote up
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    Throwable cause = e.getCause();

    // do not print exception if it is BindException.
    // we are trying to search available port below 1024. It is not good to
    // print a flood
    // of error logs during the searching.
    if (cause instanceof java.net.BindException) {
        return;
    }

    LOG.error("Exception on connection to " + getRemoteAddress(), e.getCause());

    // close the channel unless we are connecting and it is
    // NotYetConnectedException
    if (!((cause instanceof NotYetConnectedException)
            && _connection.getConnectionState().equals(Connection.State.CONNECTING))) {
        ctx.getChannel().close();
    }
}
 
Example 7
Source File: StormClientHandler.java    From jstorm with Apache License 2.0 5 votes vote down vote up
/**
 * @see org.jboss.netty.channel.SimpleChannelUpstreamHandler#exceptionCaught(org.jboss.netty.channel.ChannelHandlerContext,
 * org.jboss.netty.channel.ExceptionEvent)
 */
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent event) {
    Throwable cause = event.getCause();
    if (!being_closed.get()) {
        if (!(cause instanceof ConnectException)) {
            LOG.info("Connection failed:" + client.getRemoteAddr(), cause);
        }

        client.exceptionChannel(event.getChannel());
        client.reconnect();
    }
}
 
Example 8
Source File: BgpChannelHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {

    log.error("[exceptionCaught]: " + e.toString());

    if (e.getCause() instanceof ClosedChannelException) {
        bgpController.activeSessionExceptionAdd(peerAddr, e.getCause().toString());
        log.debug("Channel for bgp {} already closed", getPeerInfoString());
    } else if (e.getCause() instanceof IOException) {
        log.error("Disconnecting peer {} due to IO Error: {}", getPeerInfoString(), e.getCause().getMessage());
        bgpController.closedSessionExceptionAdd(peerAddr, e.getCause().toString());
        if (log.isDebugEnabled()) {
            // still print stack trace if debug is enabled
            log.debug("StackTrace for previous Exception: ", e.getCause());
        }
        stopSessionTimers();
        ctx.getChannel().close();
    } else if (e.getCause() instanceof BgpParseException) {
        byte[] data = new byte[] {};
        BgpParseException errMsg = (BgpParseException) e.getCause();
        byte errorCode = errMsg.getErrorCode();
        byte errorSubCode = errMsg.getErrorSubCode();
        bgpController.activeSessionExceptionAdd(peerAddr, e.getCause().toString());
        ChannelBuffer tempCb = errMsg.getData();
        if (tempCb != null) {
            int dataLength = tempCb.readableBytes();
            data = new byte[dataLength];
            tempCb.readBytes(data, 0, dataLength);
        }
        sendNotification(errorCode, errorSubCode, data);
    } else if (e.getCause() instanceof RejectedExecutionException) {
        log.warn("Could not process message: queue full");
        bgpController.activeSessionExceptionAdd(peerAddr, e.getCause().toString());
    } else {
        stopSessionTimers();
        log.error("Error while processing message from peer " + getPeerInfoString() + "state " + this.state);
        bgpController.closedSessionExceptionAdd(peerAddr, e.getCause().toString());
        ctx.getChannel().close();
    }
}
 
Example 9
Source File: ManageSieveChannelUpstreamHandler.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    try (Closeable closeable = ManageSieveMDCContext.from(ctx, attributes)) {
        logger.warn("Error while processing ManageSieve request", e.getCause());

        if (e.getCause() instanceof TooLongFrameException) {
            // Max line length exceeded
            // See also JAMES-1190
            ((ChannelManageSieveResponseWriter) ctx.getAttachment()).write("NO Maximum command line length exceeded");
        } else if (e.getCause() instanceof SessionTerminatedException) {
            ((ChannelManageSieveResponseWriter) ctx.getAttachment()).write("OK channel is closing");
            logout(ctx);
        }
    }
}
 
Example 10
Source File: TestDelegationTokenRemoteFetcher.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
    throws Exception {
  Channel ch = e.getChannel();
  Throwable cause = e.getCause();

  if (LOG.isDebugEnabled())
    LOG.debug(cause.getMessage());
  ch.close().addListener(ChannelFutureListener.CLOSE);
}
 
Example 11
Source File: ProgrammableTSOServer.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
    if (e.getCause() instanceof ClosedChannelException) {
        return;
    }
    LOG.warn("TSOHandler: Unexpected exception from downstream.", e.getCause());
    Channels.close(e.getChannel());
}
 
Example 12
Source File: TSOChannelHandler.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
    if (e.getCause() instanceof ClosedChannelException) {
        LOG.warn("ClosedChannelException caught. Cause: ", e.getCause());
        return;
    }
    LOG.warn("Unexpected exception from downstream. Closing channel {} {}", ctx.getChannel(), e.getCause());
    ctx.getChannel().close();
}
 
Example 13
Source File: TestDelegationTokenRemoteFetcher.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
    throws Exception {
  Channel ch = e.getChannel();
  Throwable cause = e.getCause();

  if (LOG.isDebugEnabled())
    LOG.debug(cause.getMessage());
  ch.close().addListener(ChannelFutureListener.CLOSE);
}
 
Example 14
Source File: NettyTransport.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
protected void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    if (!lifecycle.started()) {
        // ignore
        return;
    }
    if (isCloseConnectionException(e.getCause())) {
        logger.trace("close connection exception caught on transport layer [{}], disconnecting from relevant node", e.getCause(), ctx.getChannel());
        // close the channel, which will cause a node to be disconnected if relevant
        ctx.getChannel().close();
        disconnectFromNodeChannel(ctx.getChannel(), e.getCause());
    } else if (isConnectException(e.getCause())) {
        logger.trace("connect exception caught on transport layer [{}]", e.getCause(), ctx.getChannel());
        // close the channel as safe measure, which will cause a node to be disconnected if relevant
        ctx.getChannel().close();
        disconnectFromNodeChannel(ctx.getChannel(), e.getCause());
    } else if (e.getCause() instanceof CancelledKeyException) {
        logger.trace("cancelled key exception caught on transport layer [{}], disconnecting from relevant node", e.getCause(), ctx.getChannel());
        // close the channel as safe measure, which will cause a node to be disconnected if relevant
        ctx.getChannel().close();
        disconnectFromNodeChannel(ctx.getChannel(), e.getCause());
    } else if (e.getCause() instanceof SizeHeaderFrameDecoder.HttpOnTransportException) {
        // in case we are able to return data, serialize the exception content and sent it back to the client
        if (ctx.getChannel().isOpen()) {
            ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(e.getCause().getMessage().getBytes(Charsets.UTF_8));
            ChannelFuture channelFuture = ctx.getChannel().write(buffer);
            channelFuture.addListener(new ChannelFutureListener() {
                @Override
                public void operationComplete(ChannelFuture future) throws Exception {
                    future.getChannel().close();
                }
            });
        }
    } else {
        logger.warn("exception caught on transport layer [{}], closing connection", e.getCause(), ctx.getChannel());
        // close the channel, which will cause a node to be disconnected if relevant
        ctx.getChannel().close();
        disconnectFromNodeChannel(ctx.getChannel(), e.getCause());
    }
}
 
Example 15
Source File: FpmSessionHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
        throws Exception {
    if (e.getCause() instanceof ReadTimeoutException) {
        log.warn("Haven't heard from FPM client for a while");
    } else {
        log.error("Exception thrown while handling FPM message", e.getCause());
    }
    if (channel != null) {
        channel.close();
    }
    handleDisconnect();
}
 
Example 16
Source File: AbstractRPCChannelHandler.java    From floodlight_with_topoguard with Apache License 2.0 4 votes vote down vote up
@Override
@LogMessageDocs({
    @LogMessageDoc(level="ERROR",
            message="[{id}->{id}] Disconnecting client due to read timeout",
            explanation="The connected client has failed to send any " +
                        "messages or respond to echo requests",
            recommendation=LogMessageDoc.CHECK_CONTROLLER),
    @LogMessageDoc(level="ERROR",
            message="[{id}->{id}] Disconnecting RPC node due to " +
                "handshake timeout",
            explanation="The remote node did not complete the handshake",
            recommendation=LogMessageDoc.CHECK_CONTROLLER),
            @LogMessageDoc(level="ERROR",
            message="[{id}->{id}] IOException: {message}",
            explanation="There was an error communicating with the " + 
                        "remote client",
            recommendation=LogMessageDoc.GENERIC_ACTION),
            @LogMessageDoc(level="ERROR",
            message="[{id}->{id}] ConnectException: {message} {error}",
            explanation="There was an error connecting to the " + 
                        "remote node",
            recommendation=LogMessageDoc.GENERIC_ACTION),
    @LogMessageDoc(level="ERROR",
            message="[{}->{}] An error occurred on RPC channel",
            explanation="An error occurred processing the message",
            recommendation=LogMessageDoc.GENERIC_ACTION),
})
public void exceptionCaught(ChannelHandlerContext ctx,
                            ExceptionEvent e) throws Exception {
    if (e.getCause() instanceof ReadTimeoutException) {
        // read timeout
        logger.error("[{}->{}] Disconnecting RPC node due to read timeout",
                     getLocalNodeIdString(), getRemoteNodeIdString());
        ctx.getChannel().close();
    } else if (e.getCause() instanceof HandshakeTimeoutException) {
        // read timeout
        logger.error("[{}->{}] Disconnecting RPC node due to " +
                "handshake timeout",
                getLocalNodeIdString(), getRemoteNodeIdString());
        ctx.getChannel().close();
    } else if (e.getCause() instanceof ConnectException ||
               e.getCause() instanceof IOException) {
        logger.debug("[{}->{}] {}: {}", 
                     new Object[] {getLocalNodeIdString(),
                                   getRemoteNodeIdString(), 
                                   e.getCause().getClass().getName(),
                                   e.getCause().getMessage()});
    } else {
        logger.error("[{}->{}] An error occurred on RPC channel",
                     new Object[]{getLocalNodeIdString(), 
                                  getRemoteNodeIdString(),
                                  e.getCause()});
        ctx.getChannel().close();
    }
}
 
Example 17
Source File: OFChannelHandler.java    From floodlight_with_topoguard with Apache License 2.0 4 votes vote down vote up
@Override
@LogMessageDocs({
    @LogMessageDoc(level="ERROR",
            message="Disconnecting switch {switch} due to read timeout",
            explanation="The connected switch has failed to send any " +
                        "messages or respond to echo requests",
            recommendation=LogMessageDoc.CHECK_SWITCH),
    @LogMessageDoc(level="ERROR",
            message="Disconnecting switch {switch}: failed to " +
                    "complete handshake",
            explanation="The switch did not respond correctly " +
                        "to handshake messages",
            recommendation=LogMessageDoc.CHECK_SWITCH),
    @LogMessageDoc(level="ERROR",
            message="Disconnecting switch {switch} due to IO Error: {}",
            explanation="There was an error communicating with the switch",
            recommendation=LogMessageDoc.CHECK_SWITCH),
    @LogMessageDoc(level="ERROR",
            message="Disconnecting switch {switch} due to switch " +
                    "state error: {error}",
            explanation="The switch sent an unexpected message",
            recommendation=LogMessageDoc.CHECK_SWITCH),
    @LogMessageDoc(level="ERROR",
            message="Disconnecting switch {switch} due to " +
                    "message parse failure",
            explanation="Could not parse a message from the switch",
            recommendation=LogMessageDoc.CHECK_SWITCH),
    @LogMessageDoc(level="ERROR",
            message="Terminating controller due to storage exception",
            explanation=Controller.ERROR_DATABASE,
            recommendation=LogMessageDoc.CHECK_CONTROLLER),
    @LogMessageDoc(level="ERROR",
            message="Could not process message: queue full",
            explanation="OpenFlow messages are arriving faster than " +
                        " the controller can process them.",
            recommendation=LogMessageDoc.CHECK_CONTROLLER),
    @LogMessageDoc(level="ERROR",
            message="Error while processing message " +
                    "from switch {switch} {cause}",
            explanation="An error occurred processing the switch message",
            recommendation=LogMessageDoc.GENERIC_ACTION)
})
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
        throws Exception {
    if (e.getCause() instanceof ReadTimeoutException) {
        // switch timeout
        log.error("Disconnecting switch {} due to read timeout",
                             getSwitchInfoString());
        counters.switchDisconnectReadTimeout.updateCounterWithFlush();
        ctx.getChannel().close();
    } else if (e.getCause() instanceof HandshakeTimeoutException) {
        log.error("Disconnecting switch {}: failed to complete handshake",
                  getSwitchInfoString());
        counters.switchDisconnectHandshakeTimeout.updateCounterWithFlush();
        ctx.getChannel().close();
    } else if (e.getCause() instanceof ClosedChannelException) {
        log.debug("Channel for sw {} already closed", getSwitchInfoString());
    } else if (e.getCause() instanceof IOException) {
        log.error("Disconnecting switch {} due to IO Error: {}",
                  getSwitchInfoString(), e.getCause().getMessage());
        if (log.isDebugEnabled()) {
            // still print stack trace if debug is enabled
            log.debug("StackTrace for previous Exception: ", e.getCause());
        }
        counters.switchDisconnectIOError.updateCounterWithFlush();
        ctx.getChannel().close();
    } else if (e.getCause() instanceof SwitchStateException) {
        log.error("Disconnecting switch {} due to switch state error: {}",
                  getSwitchInfoString(), e.getCause().getMessage());
        if (log.isDebugEnabled()) {
            // still print stack trace if debug is enabled
            log.debug("StackTrace for previous Exception: ", e.getCause());
        }
        counters.switchDisconnectSwitchStateException.updateCounterWithFlush();
        ctx.getChannel().close();
    } else if (e.getCause() instanceof MessageParseException) {
        log.error("Disconnecting switch "
                             + getSwitchInfoString() +
                             " due to message parse failure",
                             e.getCause());
        counters.switchDisconnectParseError.updateCounterWithFlush();
        ctx.getChannel().close();
    } else if (e.getCause() instanceof StorageException) {
        log.error("Terminating controller due to storage exception",
                  e.getCause());
        this.controller.terminate();
    } else if (e.getCause() instanceof RejectedExecutionException) {
        log.warn("Could not process message: queue full");
        counters.rejectedExecutionException.updateCounterWithFlush();
    } else {
        log.error("Error while processing message from switch "
                             + getSwitchInfoString()
                             + "state " + this.state, e.getCause());
        counters.switchDisconnectOtherException.updateCounterWithFlush();
        ctx.getChannel().close();
    }
}
 
Example 18
Source File: ImapChannelUpstreamHandler.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    try (Closeable closeable = IMAPMDCContext.from(ctx, attributes)) {
        LOGGER.warn("Error while processing imap request", e.getCause());

        if (e.getCause() instanceof TooLongFrameException) {

            // Max line length exceeded
            // See RFC 2683 section 3.2.1
            //
            // "For its part, a server should allow for a command line of at
            // least
            // 8000 octets. This provides plenty of leeway for accepting
            // reasonable
            // length commands from clients. The server should send a BAD
            // response
            // to a command that does not end within the server's maximum
            // accepted
            // command length."
            //
            // See also JAMES-1190
            ImapResponseComposer composer = (ImapResponseComposer) ctx.getAttachment();
            composer.untaggedResponse(ImapConstants.BAD + " failed. Maximum command line length exceeded");

        } else {

            // logout on error not sure if that is the best way to handle it
            final ImapSession imapSession = (ImapSession) attributes.get(ctx.getChannel());
            if (imapSession != null) {
                imapSession.logout();
            }

            // Make sure we close the channel after all the buffers were flushed out
            Channel channel = ctx.getChannel();
            if (channel.isConnected()) {
                channel.write(ChannelBuffers.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
            }

        }
    }
}
 
Example 19
Source File: NettyServerHandler.java    From migration-tool with Apache License 2.0 4 votes vote down vote up
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
	if (!(e.getCause() instanceof IOException)) {
		log.error("catch some exception not IOException", e.getCause());
	}
}
 
Example 20
Source File: NettyClientHandler.java    From migration-tool with Apache License 2.0 4 votes vote down vote up
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
	if (!(e.getCause() instanceof IOException)) {
		log.error("catch some exception not IOException", e.getCause());
	}
}