Java Code Examples for org.jboss.netty.channel.ExceptionEvent

The following are top voted examples for showing how to use org.jboss.netty.channel.ExceptionEvent. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: hadoop   File: ShuffleHandler.java   View source code 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 2
Project: athena   File: OspfInterfaceChannelHandler.java   View source code 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent
        e) throws Exception {
    log.debug("[exceptionCaught]: " + e.toString());
    if (e.getCause() instanceof ReadTimeoutException) {
        log.debug("Disconnecting device {} due to read timeout", e.getChannel().getRemoteAddress());
        return;
    } else if (e.getCause() instanceof ClosedChannelException) {
        log.debug("Channel for OSPF {} already closed", e.getChannel().getRemoteAddress());
    } else if (e.getCause() instanceof IOException) {
        log.debug("Disconnecting OSPF {} due to IO Error: {}", e.getChannel().getRemoteAddress(),
                  e.getCause().getMessage());
    } else if (e.getCause() instanceof OspfParseException) {
        OspfParseException errMsg = (OspfParseException) e.getCause();
        byte errorCode = errMsg.errorCode();
        byte errorSubCode = errMsg.errorSubCode();
        log.debug("Error while parsing message from OSPF {}, ErrorCode {}",
                  e.getChannel().getRemoteAddress(), errorCode);
    } else if (e.getCause() instanceof RejectedExecutionException) {
        log.debug("Could not process message: queue full");
    } else {
        log.debug("Error while processing message from OSPF {}, {}",
                  e.getChannel().getRemoteAddress(), e.getCause().getMessage());
    }
}
 
Example 3
Project: athena   File: IsisChannelHandler.java   View source code 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    if (e.getCause() instanceof ReadTimeoutException) {
        log.debug("Disconnecting device {} due to read timeout", e.getChannel().getRemoteAddress());
        return;
    } else if (e.getCause() instanceof ClosedChannelException) {
        log.debug("Channel for ISIS {} already closed", e.getChannel().getRemoteAddress());
    } else if (e.getCause() instanceof IOException) {
        log.debug("Disconnecting ISIS {} due to IO Error: {}", e.getChannel().getRemoteAddress(),
                  e.getCause().getMessage());
    } else if (e.getCause() instanceof IsisParseException) {
        IsisParseException errMsg = (IsisParseException) e.getCause();
        byte errorCode = errMsg.errorCode();
        byte errorSubCode = errMsg.errorSubCode();
        log.debug("Error while parsing message from ISIS {}, ErrorCode {}",
                  e.getChannel().getRemoteAddress(), errorCode);
    } else if (e.getCause() instanceof RejectedExecutionException) {
        log.debug("Could not process message: queue full");
    } else {
        log.debug("Error while processing message from ISIS {}, {}",
                  e.getChannel().getRemoteAddress(), e.getCause().getMessage());
    }
}
 
Example 4
Project: aliyun-oss-hadoop-fs   File: ShuffleHandler.java   View source code 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 5
Project: bigstreams   File: ServerUtil.java   View source code 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
		throws Exception {
	System.out.println("Server Exception Caught");
	e.getCause().printStackTrace();

	/**
	 * Very important to respond here.
	 * The agent will always be listening for some kind of feedback.
	 */
	ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
	buffer.writeInt(500);

	ChannelFuture future = e.getChannel().write(buffer);

	future.addListener(ChannelFutureListener.CLOSE);

}
 
Example 6
Project: bigstreams   File: PerChannelBookieClient.java   View source code 6 votes vote down vote up
/**
 * Called by netty when an exception happens in one of the netty threads
 * (mostly due to what we do in the netty threads)
 */
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    Throwable t = e.getCause();
    if (t instanceof CorruptedFrameException || t instanceof TooLongFrameException) {
        LOG.error("Corrupted fram recieved from bookie: " + e.getChannel().getRemoteAddress());
        return;
    }
    if (t instanceof IOException) {
        // these are thrown when a bookie fails, logging them just pollutes
        // the logs (the failure is logged from the listeners on the write
        // operation), so I'll just ignore it here.
        return;
    }

    LOG.fatal("Unexpected exception caught by bookie client channel handler", t);
    // Since we are a library, cant terminate App here, can we?
}
 
Example 7
Project: big-c   File: ShuffleHandler.java   View source code 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 8
Project: fastcatsearch3   File: HttpTransportModule.java   View source code 6 votes vote down vote up
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
//		logger.error("exceptionCaught", e.getCause());
		if (e.getCause() instanceof ReadTimeoutException) {
			if (logger.isTraceEnabled()) {
				logger.trace("Connection timeout [{}]", ctx.getChannel().getRemoteAddress());
			}
			ctx.getChannel().close();
		} else {
			if (!isLoaded) {
				// ignore
				return;
			}
			if (!NetworkExceptionHelper.isCloseConnectionException(e.getCause())) {
//				logger.warn("Caught exception while handling client http traffic, closing connection {}", e.getCause(), ctx.getChannel());
				ctx.getChannel().close();
			} else {
//				logger.debug("Caught exception while handling client http traffic, closing connection {}", e.getCause(), ctx.getChannel());
				ctx.getChannel().close();
			}
		}
		
	}
 
Example 9
Project: BJAF3.x   File: RpcServerHandler.java   View source code 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
		throws Exception {
	Throwable te = e.getCause();
	if (te instanceof java.io.IOException) {// 网络异常,也有可能是soLinger参数引起
		return;
	}
	logger.error("Unexpected exception from downstream.{}", e.getCause());
	Channel c = e.getChannel();
	try {
		if (c.isWritable()) {
			RpcResponse res = new RpcResponse();
			res.setReturnFlag(RpcConst.ERR_CODE_SERVER_CHANNEL_EXCEPTION);
			res.setReturnMsg(logger.getStackTraceInfo(e.getCause()));
			c.write(res);
		}
	} finally {
		c.close();
	}
	// super.exceptionCaught(ctx, e);
}
 
Example 10
Project: elasticsearch-client-http   File: HttpClient.java   View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    HttpContext<R, T> httpContext = httpContextMap.get(ctx.getChannel());
    try {
        if (httpContext != null && httpContext.getListener() != null) {
            httpContext.getListener().onFailure(e.getCause());
        } else {
            Throwable t = e.getCause();
            logger.error(t.getMessage(), t);
        }
    } finally {
        ctx.getChannel().close();
        httpContextMap.remove(ctx.getChannel());
    }
}
 
Example 11
Project: nfs-client-java   File: ClientIOHandler.java   View source code 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 12
Project: hadoop-2.6.0-cdh5.4.3   File: ShuffleHandler.java   View source code 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 13
Project: hadoop-EAR   File: ShuffleHandler.java   View source code 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 14
Project: hadoop-plus   File: ShuffleHandler.java   View source code 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 15
Project: parallec   File: TcpWorker.java   View source code 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
    
    if(!hasCaughtException){
        hasCaughtException=true;
        e.getChannel().close();
        String errMsg = e.getCause().getLocalizedMessage();
        logger.debug("TCP Handler exceptionCaught: {} . ", errMsg);
        
        int statusCodeInt = 1;
        String statusCode = statusCodeInt + " FAILURE";
        
        tcpWorker.onComplete(tcpWorker.responseSb.toString(), true, 
                errMsg, errMsg, statusCode, statusCodeInt);
        
    }
}
 
Example 16
Project: parallec   File: UdpWorker.java   View source code 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {

    if (!hasCaughtException) {
        hasCaughtException = true;

        String errMsg = e.getCause().toString();
        logger.debug("UDP Handler exceptionCaught: {} . ", errMsg);
        e.getChannel().close();

        int statusCodeInt = 1;
        String statusCode = statusCodeInt + " FAILURE";

        udpWorker.onComplete(udpWorker.responseSb.toString(), true,
                errMsg, errMsg, statusCode, statusCodeInt);
    }
}
 
Example 17
Project: FlexMap   File: ShuffleHandler.java   View source code 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 18
Project: apm-agent   File: PinpointSocketHandler.java   View source code 6 votes vote down vote up
@Override
    public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
        Throwable cause = e.getCause();
        if (state.getState() == State.INIT_RECONNECT) {
            // removed stackTrace when reconnect. so many logs.
            logger.info("exceptionCaught() reconnect failed. state:{} {} Caused:{}", state.getString(), e.getChannel(), cause.getMessage());
        } else {
            logger.warn("exceptionCaught() UnexpectedError happened. state:{} {} Caused:{}", state.getString(), e.getChannel(), cause.getMessage(), cause);
        }
        // need to handle a error more precisely.
        // below code dose not reconnect when node on channel is just hang up or dead without specific reasons.

//        state.setClosed();
//        Channel channel = e.getChannel();
//        if (channel.isConnected()) {
//            channel.close();
//        }

    }
 
Example 19
Project: hops   File: ShuffleHandler.java   View source code 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 20
Project: my-dev   File: NettyServerUpstreamHandler.java   View source code 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    Throwable t = e.getCause();

    if (this.channelHandler != null) {
        this.channelHandler.onError(this.createContext(t));
    }

    e.getChannel().close();

    if (t instanceof IOException) {
        this.ioErrorLogger.error(Text.ERROR_AT_SERVER, t);
    } else {
        this.logger.error(Text.ERROR_AT_SERVER, t);
    }
}
 
Example 21
Project: honoumi   File: HttpRequestHandler.java   View source code 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
	Channel channel = ctx.getChannel();

	logger.error(
		"[channel exception] {} \n"
			+
			"[channel status] channelIsOpen={}, channelIsBound={}, channelIsWriteable={}, channelIsReadable={}, channelIsConnected={} \n"
			+
			"[stacktrace] {}",
		e,
		channel.isOpen(), channel.isBound(), channel.isWritable(), channel.isReadable(), channel.isConnected(),
		Utils.stackTraceToStr(e.getCause())
		);

	if (ctx.getChannel().isOpen()) {
		ctx.getChannel().close();
	}
}
 
Example 22
Project: hadoop-TCP   File: ShuffleHandler.java   View source code 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 23
Project: BettaServer   File: BettaUdpFileServerHandler.java   View source code 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 ;
    }
    
    cause.printStackTrace( ) ;
    if( ch.isConnected( ) )
    {
        sendError( ctx, INTERNAL_SERVER_ERROR ) ;
    }
}
 
Example 24
Project: rest4j   File: RAPResponseHandler.java   View source code 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception
{
  TransportCallback<RestResponse> callback = removeAttachment(ctx);
  if (callback != null)
  {
    LOG.debug(e.getChannel().getRemoteAddress() + ": exception on active channel", e.getCause());
    callback.onResponse(TransportResponseImpl.<RestResponse>error(
            HttpNettyClient.toException(e.getCause()), Collections.<String,String>emptyMap()));
  }
  else
  {
    LOG.error(e.getChannel().getRemoteAddress() + ": exception on idle channel or during handling of response", e.getCause());
  }
  super.exceptionCaught(ctx, e);
}
 
Example 25
Project: hardfs   File: ShuffleHandler.java   View source code 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 26
Project: hadoop-on-lustre2   File: ShuffleHandler.java   View source code 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 27
Project: onos   File: OspfInterfaceChannelHandler.java   View source code 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
    log.debug("[exceptionCaught]: " + e.toString());
    if (e.getCause() instanceof ReadTimeoutException) {
        log.debug("Disconnecting device {} due to read timeout", e.getChannel().getRemoteAddress());
        return;
    } else if (e.getCause() instanceof ClosedChannelException) {
        log.debug("Channel for OSPF {} already closed", e.getChannel().getRemoteAddress());
    } else if (e.getCause() instanceof IOException) {
        log.debug("Disconnecting OSPF {} due to IO Error: {}", e.getChannel().getRemoteAddress(),
                  e.getCause().getMessage());
    } else if (e.getCause() instanceof OspfParseException) {
        OspfParseException errMsg = (OspfParseException) e.getCause();
        byte errorCode = errMsg.errorCode();
        byte errorSubCode = errMsg.errorSubCode();
        log.debug("Error while parsing message from OSPF {}, ErrorCode {}",
                  e.getChannel().getRemoteAddress(), errorCode);
    } else if (e.getCause() instanceof RejectedExecutionException) {
        log.debug("Could not process message: queue full");
    } else {
        log.debug("Error while processing message from OSPF {}, {}",
                  e.getChannel().getRemoteAddress(), e.getCause().getMessage());
    }
}
 
Example 28
Project: onos   File: IsisChannelHandler.java   View source code 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    if (e.getCause() instanceof ReadTimeoutException) {
        log.debug("Disconnecting device {} due to read timeout", e.getChannel().getRemoteAddress());
        return;
    } else if (e.getCause() instanceof ClosedChannelException) {
        log.debug("Channel for ISIS {} already closed", e.getChannel().getRemoteAddress());
    } else if (e.getCause() instanceof IOException) {
        log.debug("Disconnecting ISIS {} due to IO Error: {}", e.getChannel().getRemoteAddress(),
                  e.getCause().getMessage());
    } else if (e.getCause() instanceof IsisParseException) {
        IsisParseException errMsg = (IsisParseException) e.getCause();
        byte errorCode = errMsg.errorCode();
        byte errorSubCode = errMsg.errorSubCode();
        log.debug("Error while parsing message from ISIS {}, ErrorCode {}",
                  e.getChannel().getRemoteAddress(), errorCode);
    } else if (e.getCause() instanceof RejectedExecutionException) {
        log.debug("Could not process message: queue full");
    } else {
        log.debug("Error while processing message from ISIS {}, {}",
                  e.getChannel().getRemoteAddress(), e.getCause().getMessage());
    }
}
 
Example 29
Project: RDFS   File: ShuffleHandler.java   View source code 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 30
Project: netty-isdn-transport   File: IsdnConnectionHandler.java   View source code 6 votes vote down vote up
@Transition(on = EXCEPTION_CAUGHT, in = PLCI, next = PLCI_IDLE)
public void error(IsdnChannel channel, StateContext stateCtx, ChannelHandlerContext ctx, ExceptionEvent event) {
    LOGGER.error("Unexpected error.", event.getCause());
    if (!channel.isConnected()) {
        // retrieve CHANNEL_CONNECTED event and clear attribute
        ChannelStateEvent channelConnected = (ChannelStateEvent) stateCtx.getAttribute(ISDN_CONNECTED_EVENT_ATTR);
        stateCtx.setAttribute(ISDN_CONNECTED_EVENT_ATTR, null);
        try {
         // set FAILED on connectFuture 
         channelConnected.getFuture().setFailure(new Exception(format("ERROR - %s", event.getCause().getMessage())));
        } catch (Throwable t) {
        	// avoid NPE when connection is already closed – really doesn't
        	// matter finding a new error – ignore
        }
    } else {
        ctx.sendUpstream(event);
    }
    close(channel);
}
 
Example 31
Project: fastcatsearch   File: HttpTransportModule.java   View source code 6 votes vote down vote up
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
//		logger.error("exceptionCaught", e.getCause());
		if (e.getCause() instanceof ReadTimeoutException) {
			if (logger.isTraceEnabled()) {
				logger.trace("Connection timeout [{}]", ctx.getChannel().getRemoteAddress());
			}
			ctx.getChannel().close();
		} else {
			if (!isLoaded) {
				// ignore
				return;
			}
			if (!NetworkExceptionHelper.isCloseConnectionException(e.getCause())) {
//				logger.warn("Caught exception while handling client http traffic, closing connection {}", e.getCause(), ctx.getChannel());
				ctx.getChannel().close();
			} else {
//				logger.debug("Caught exception while handling client http traffic, closing connection {}", e.getCause(), ctx.getChannel());
				ctx.getChannel().close();
			}
		}
		
	}
 
Example 32
Project: zookeeper.dsc   File: PerChannelBookieClient.java   View source code 6 votes vote down vote up
/**
 * Called by netty when an exception happens in one of the netty threads
 * (mostly due to what we do in the netty threads)
 */
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    Throwable t = e.getCause();
    if (t instanceof CorruptedFrameException || t instanceof TooLongFrameException) {
        LOG.error("Corrupted fram recieved from bookie: " + e.getChannel().getRemoteAddress());
        return;
    }
    if (t instanceof IOException) {
        // these are thrown when a bookie fails, logging them just pollutes
        // the logs (the failure is logged from the listeners on the write
        // operation), so I'll just ignore it here.
        return;
    }

    LOG.fatal("Unexpected exception caught by bookie client channel handler", t);
    // Since we are a library, cant terminate App here, can we?
}
 
Example 33
Project: jersey-netty   File: NettyContainer.java   View source code 6 votes vote down vote up
public void invalidRequestSent(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    Channel channel = ctx.getChannel();
    if (channel == null || !channel.isOpen()) {
        log.debug("Not writing any response, channel is already closed.", e.getCause());
        return;
    }

    final DefaultHttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_0, HttpResponseStatus.BAD_REQUEST);
    response.headers().add(HttpHeaders.Names.CONTENT_TYPE, "text/plain");
    response.headers().add(HttpHeaders.Names.CONNECTION, "close");
    final ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    new ChannelBufferOutputStream(buffer).writeBytes("Your client has sent a malformed or illegal request.\n");
    response.setContent(buffer);

    final ChannelFuture channelFuture = channel.write(response);

    channelFuture.addListener(ChannelFutureListener.CLOSE);
}
 
Example 34
Project: tez   File: ShuffleHandler.java   View source code 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 35
Project: tez   File: ShuffleHandler.java   View source code 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 36
Project: httptunnel   File: HttpTunnelClientChannelPollHandler.java   View source code 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
	final Throwable error = e.getCause();

	if (error instanceof IOException // Connection reset etc
		|| error instanceof ClosedChannelException
		|| error instanceof IllegalArgumentException) {  // Invalid protocol format - bots etc
		if (LOG.isDebugEnabled())
			LOG.debug("Exception from HttpTunnel send handler: " + error);

		return;
	}

	if (LOG.isWarnEnabled())
		LOG.warn("Exception from HttpTunnel poll handler: " + error);
}
 
Example 37
Project: httptunnel   File: HttpTunnelClientChannelSendHandler.java   View source code 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
	final Throwable error = e.getCause();

	if (error instanceof IOException // Connection reset etc
		|| error instanceof ClosedChannelException || error instanceof IllegalArgumentException) { // Invalid
																									// protocol
																									// format
																									// -
																									// bots
																									// etc
		if (LOG.isDebugEnabled())
			LOG.debug("Exception from HttpTunnel send handler: " + error);

		return;
	}

	if (LOG.isWarnEnabled())
		LOG.warn("Exception from HttpTunnel send handler: " + error);
}
 
Example 38
Project: httptunnel   File: HttpTunnelAcceptedChannelHandler.java   View source code 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
	final Throwable error = e.getCause();

	if (error instanceof IOException // Connection reset etc
		|| error instanceof ClosedChannelException || error instanceof IllegalArgumentException) { // Invalid
																									// protocol
																									// format
																									// -
																									// bots
																									// etc
		if (LOG.isDebugEnabled())
			LOG.debug("Exception from HttpTunnel send handler: " + error);

		return;
	}

	if (LOG.isWarnEnabled())
		LOG.warn("Exception from HttpTunnel accepted channel handler: " + error);
}
 
Example 39
Project: voyage   File: NettyRpcServerHandler.java   View source code 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
		throws Exception {
	RpcRequest request = (RpcRequest) ctx.getAttachment();
	if (e.getCause() instanceof ReadTimeoutException) {
		// The connection was OK but there was no traffic for last period.
		logger.warn("Disconnecting due to no inbound traffic");
	} else {
		logger.error("", e);
	}
	e.getChannel().close().awaitUninterruptibly();
}
 
Example 40
Project: EatDubbo   File: NettyHandler.java   View source code 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), url, handler);
    try {
        handler.caught(channel, e.getCause());
    } finally {
        NettyChannel.removeChannelIfDisconnected(ctx.getChannel());
    }
}