protected void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (cause instanceof ReadTimeoutException) { if (logger.isTraceEnabled()) { logger.trace("Connection timeout [{}]", ctx.channel().remoteAddress()); } ctx.channel().close(); } else { if (!lifecycle.started()) { // ignore return; } if (!NetworkExceptionHelper.isCloseConnectionException(cause)) { logger.warn( (Supplier<?>) () -> new ParameterizedMessage( "caught exception while handling client http traffic, closing connection {}", ctx.channel()), cause); ctx.channel().close(); } else { logger.debug( (Supplier<?>) () -> new ParameterizedMessage( "caught exception while handling client http traffic, closing connection {}", ctx.channel()), cause); ctx.channel().close(); } } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable e) throws Exception { try { if (e.getCause() instanceof ReadTimeoutException) { ctx.write(PINGRESP).addListener( ChannelFutureListener.CLOSE_ON_FAILURE); } else { ctx.channel().close(); } } catch (Throwable t) { t.printStackTrace(); ctx.channel().close(); } e.printStackTrace(); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (cause instanceof ReadTimeoutException) { LOG.warn("[{}] The channel was closed because a read timed out", connectionId); } ResponseCollector collector = responseCollector.getAndSet(null); if (collector != null) { collector.completeExceptionally(cause); } else { // this exception can't get back to the client via a future, // use the connection exception handler if possible if (exceptionHandler.isPresent()) { exceptionHandler.get().accept(cause); } else { super.exceptionCaught(ctx, cause); } } }
@Override public void exceptionCaught(final ChannelHandlerContext context, final Throwable cause) { if ( cause instanceof ReadTimeoutException ) { if ( CoreConfig.debug ) { Logger.debug( "Connection for {} timed out", workerContext.getSocketContext().getIP() ); } } else { Logger.error( "Encountered error..." ); cause.printStackTrace(); } context.close(); }
@Override public void run() { if (entryQ.isEmpty() || timeoutNs <= 0) { timeoutTask = null; return; } boolean refillTxnMarker = false; if (entryQ.peekFirst() == TXN_MARKER) { entryQ.removeFirst(); refillTxnMarker = true; } if (entryQ.isEmpty()) { entryQ.addFirst(TXN_MARKER); timeoutTask = null; return; } long nextDelayNs = timeoutNs - (System.nanoTime() - entryQ.peek().nanoTime); if (nextDelayNs <= 0) { exceptionCaught(ctx, ReadTimeoutException.INSTANCE); } else { timeoutTask = ctx.executor().schedule(this, nextDelayNs, TimeUnit.NANOSECONDS); if (refillTxnMarker) { entryQ.addFirst(TXN_MARKER); } } }
@Test public void testTimeout() throws InterruptedException { pool = NedisClientPoolBuilder.create() .remoteAddress(new InetSocketAddress("127.0.0.1", PORT)).database(1).build(); NedisClient client = pool.acquire().sync().getNow(); Thread.sleep(1000); assertEquals(1, pool.numPooledConns()); assertEquals(1, pool.numConns()); assertEquals(0L, client.setTimeout(100).sync().getNow().longValue()); Future<?> future = client.blpop(1, toBytes("foo")).await(); assertFalse(future.isSuccess()); assertTrue(future.cause() instanceof ReadTimeoutException); Thread.sleep(1000); assertEquals(0, pool.numPooledConns()); assertEquals(0, pool.numConns()); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { String message; if (!(cause instanceof ConnectTimeoutException) && (!(cause instanceof ConnectException) || !cause.getMessage() .contains("connection timed out"))) { if (cause instanceof ReadTimeoutException) { message = "Read timed out."; } else if (cause instanceof WriteTimeoutException) { message = "Write timed out."; } else { message = "Internal network exception."; } } else { message = "Connection timed out."; } this.disconnect(message, cause); }
private void initialize(final ChannelHandlerContext ctx) { this.lastReadTime = System.currentTimeMillis(); this.timeoutTask = ctx.executor().schedule(new Runnable() { @Override public void run() { if (ctx.channel().isOpen()) { long untilTimeout = timeoutTime - (System.currentTimeMillis() - lastReadTime); if (untilTimeout <= 0) { ctx.fireExceptionCaught(ReadTimeoutException.INSTANCE); } else { ctx.executor().schedule(this, untilTimeout, TimeUnit.MILLISECONDS); } } } }, this.timeoutTime, TimeUnit.MILLISECONDS); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (ctx.channel().isActive()) { LOG.error("Exception occurred while processing connection pipeline", cause); if ((cause instanceof InvalidEncodingException) || (cause instanceof TooLongFrameException || (cause instanceof DecoderException))) { LOG.info("Disconnecting channel to ovsdb {}", ctx.channel()); ctx.channel().disconnect(); return; } /* In cases where a connection is quickly established and the closed Catch the IOException and close the channel. Similarly if the peer is powered off, Catch the read time out exception and close the channel */ if ((cause instanceof IOException) || (cause instanceof ReadTimeoutException)) { LOG.info("Closing channel to ovsdb {}", ctx.channel()); ctx.channel().close(); return; } LOG.error("Exception was not handled by the exception handler, re-throwing it for next handler"); ctx.fireExceptionCaught(cause); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { if (cause instanceof ReadTimeoutException) { log.error("Connection closed because of ReadTimeoutException {}", cause.getMessage()); } else if (cause instanceof ClosedChannelException) { log.error("ClosedChannelException occurred"); return; } else if (cause instanceof RejectedExecutionException) { log.error("Could not process message: queue full"); } else if (cause instanceof IOException) { log.error("IOException occurred"); } else { log.error("Error while processing message from switch {}", cause.getMessage()); } channel.close(); }
@Override public void exceptionCaught(ChannelHandlerContext context, Throwable cause) throws Exception { Channel channel = context.channel(); if(cause instanceof IOException && cause.getMessage().equals("Connection reset by peer")) { // ignore } else if(cause instanceof ReadTimeoutException) { // ignore } else if(cause instanceof DecoderException) { // ignore } else { cause.printStackTrace(); } if(channel.isOpen()) { channel.close(); } }
/** * Is called when a read timeout was detected. */ protected void readTimedOut(ChannelHandlerContext ctx) throws Exception { if (!closed) { ctx.fireExceptionCaught(ReadTimeoutException.INSTANCE); ctx.close(); closed = true; } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (channel.isDiscoveryMode()) { loggerNet.trace("Handshake failed: " + cause); } else { if (cause instanceof IOException || cause instanceof ReadTimeoutException) { loggerNet.debug("Handshake failed: " + ctx.channel().remoteAddress() + ": " + cause); } else { loggerNet.warn("Handshake failed: ", cause); } } ctx.close(); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (cause instanceof ReadTimeoutException) { HttpTransport transport = getTransport(ctx); if (transport != null) { transport.handleTimeout(ctx); } } else { cause.printStackTrace(); ctx.close(); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { log.error("[{}] Unexpected Exception: {}", sessionId, cause); try { if (cause.getCause() instanceof ReadTimeoutException) { ctx.write(PINGRESP).addListener(ChannelFutureListener.CLOSE_ON_FAILURE); } else { ctx.close(); } } catch (Throwable t) { t.printStackTrace(); ctx.close(); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (cause instanceof ReadTimeoutException) { handleReadTimeout(ctx); } else if (cause instanceof WriteTimeoutException) { handleWriteTimeout(ctx); } else { super.exceptionCaught(ctx, cause); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { ctx.close(); if (cause instanceof ReadTimeoutException) { System.out.println("No reply received from " + addr); } else { System.out.println("Unexpected exception: " + cause.getMessage()); throw new RuntimeException(cause); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (cause instanceof ReadTimeoutException) { // read timeout logger.error("[{}->{}] Disconnecting RPC node due to read timeout", getLocalNodeIdString(), getRemoteNodeIdString()); ctx.channel().close(); } else if (cause instanceof HandshakeTimeoutException) { // read timeout logger.error("[{}->{}] Disconnecting RPC node due to " + "handshake timeout", getLocalNodeIdString(), getRemoteNodeIdString()); ctx.channel().close(); } else if (cause instanceof ConnectException || cause instanceof IOException) { logger.debug("[{}->{}] {}: {}", new Object[] {getLocalNodeIdString(), getRemoteNodeIdString(), cause.getClass().getName(), cause.getMessage()}); } else { logger.error("[{}->{}] An error occurred on RPC channel", new Object[]{getLocalNodeIdString(), getRemoteNodeIdString(), cause}); ctx.channel().close(); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (cause instanceof ReadTimeoutException) { // httpcode 504 if (context.channel().isOpen()) sendResponse(httpContext, HttpResponseBuilder.create(httpContext, HttpResponseStatus.GATEWAY_TIMEOUT)); } }
@Test public void shouldThrowExceptionOnTimeout() { mockServerClient .when(request() .withMethod("GET") .withPath("/json")) .respond(response() .withDelay(TimeUnit.MILLISECONDS, 3000)); expectedException.expect(isA(RestifyHttpException.class)); expectedException.expectCause(deeply(ReadTimeoutException.class)); myApi.json(); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (cause instanceof ReadTimeoutException) { logger.debug("Connection timed out."); onChannelInactive(ctx); } else { logger.debug("Exception caught.", cause); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if(cause instanceof ReadTimeoutException) { System.out.println("## Read Timeout. ## [Message : " + cause.getMessage() + "]"); } else { super.exceptionCaught(ctx, cause); } }
@Test public void testRequestTimeout() throws Exception { try { template.requestBody("netty4:tcp://localhost:{{port}}?textline=true&sync=true&requestTimeout=1000", "Hello Camel", String.class); fail("Should have thrown exception"); } catch (CamelExecutionException e) { ReadTimeoutException cause = assertIsInstanceOf(ReadTimeoutException.class, e.getCause()); assertNotNull(cause); } }
@Test public void testRequestTimeoutViaHeader() throws Exception { try { template.requestBodyAndHeader("netty4:tcp://localhost:{{port}}?textline=true&sync=true", "Hello Camel", NettyConstants.NETTY_REQUEST_TIMEOUT, 1000, String.class); fail("Should have thrown exception"); } catch (CamelExecutionException e) { ReadTimeoutException cause = assertIsInstanceOf(ReadTimeoutException.class, e.getCause()); assertNotNull(cause); } }
@Test public void testRequestTimeoutAndOk() throws Exception { try { template.requestBody("netty4:tcp://localhost:{{port}}?textline=true&sync=true&requestTimeout=1000", "Hello Camel", String.class); fail("Should have thrown exception"); } catch (CamelExecutionException e) { ReadTimeoutException cause = assertIsInstanceOf(ReadTimeoutException.class, e.getCause()); assertNotNull(cause); } // now we try again but this time the is no delay on server and thus faster String out = template.requestBody("netty4:tcp://localhost:{{port}}?textline=true&sync=true&requestTimeout=1000", "Hello World", String.class); assertEquals("Bye World", out); }
@Test public void testRequestTimeout() throws Exception { try { template.requestBody("netty4-http:http://localhost:{{port}}/timeout?requestTimeout=1000", "Hello Camel", String.class); fail("Should have thrown exception"); } catch (CamelExecutionException e) { ReadTimeoutException cause = assertIsInstanceOf(ReadTimeoutException.class, e.getCause()); assertNotNull(cause); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (cause instanceof ReadTimeoutException) { LOG.warn(cause.getMessage(), cause); } else { LOG.error("Fetch failed :", cause); } // this fetching will be retry IOUtils.cleanup(LOG, fc, raf); endFetch(FetcherState.FETCH_FAILED); ctx.close(); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (cause instanceof ReadTimeoutException) { LOG.warn(cause.getMessage(), cause); } else { LOG.error("Fetch failed :", cause); } // this fetching will be retry finishTime = System.currentTimeMillis(); state = TajoProtos.FetcherState.FETCH_FAILED; ctx.close(); }
@Test public void should_error_on_timeout() { InstanceWebClient fastTimeoutClient = new InstanceWebClient(headersProvider, Duration.ofMillis(10), Duration.ofMillis(10)); wireMock.stubFor(get("/foo").willReturn(ok().withFixedDelay(100))); Mono<ClientResponse> exchange = fastTimeoutClient.instance(Mono.empty()) .get() .uri(wireMock.url("/foo")) .exchange(); StepVerifier.create(exchange).verifyError(ReadTimeoutException.class); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { ctx.close(); if (cause instanceof IOException || cause instanceof ReadTimeoutException) { return; } LOGGER.error(cause.getMessage(), cause); }
@Override public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) throws Exception { // The client idled for too long, so we'll just close their channel and move on. // OR The client disconnected early // TODO: Fix ignoring all IOExceptions (some may be legitimate) if (cause instanceof ReadTimeoutException || cause instanceof IOException) { ctx.close(); return; } this.rs.getLogger().severe("An uncaught exception occurred somewhere in the pipeline:"); this.rs.getLogger().log(Level.SEVERE, cause.getMessage(), cause); cause.printStackTrace(); }