Search in sources :

Example 26 with TooLongFrameException

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.TooLongFrameException in project bookkeeper by apache.

the class PerChannelBookieClient method exceptionCaught.

/**
 * 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, Throwable cause) throws Exception {
    exceptionCounter.inc();
    if (cause instanceof CorruptedFrameException || cause instanceof TooLongFrameException) {
        LOG.error("Corrupted frame received from bookie: {}", ctx.channel().remoteAddress());
        ctx.close();
        return;
    }
    if (cause instanceof AuthHandler.AuthenticationException) {
        LOG.error("Error authenticating connection", cause);
        errorOutOutstandingEntries(BKException.Code.UnauthorizedAccessException);
        Channel c = ctx.channel();
        if (c != null) {
            closeChannel(c);
        }
        return;
    }
    if (cause instanceof DecoderException && cause.getCause() instanceof SSLHandshakeException) {
        LOG.error("TLS handshake failed", cause);
        errorOutPendingOps(BKException.Code.SecurityException);
        Channel c = ctx.channel();
        if (c != null) {
            closeChannel(c);
        }
    }
    if (cause instanceof IOException) {
        LOG.warn("Exception caught on:{} cause:", ctx.channel(), cause);
        ctx.close();
        return;
    }
    synchronized (this) {
        if (state == ConnectionState.CLOSED) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Unexpected exception caught by bookie client channel handler, " + "but the client is closed, so it isn't important", cause);
            }
        } else {
            LOG.error("Unexpected exception caught by bookie client channel handler", cause);
        }
    }
    // Since we are a library, cant terminate App here, can we?
    ctx.close();
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) TooLongFrameException(io.netty.handler.codec.TooLongFrameException) CorruptedFrameException(io.netty.handler.codec.CorruptedFrameException) EpollSocketChannel(io.netty.channel.epoll.EpollSocketChannel) Channel(io.netty.channel.Channel) LocalChannel(io.netty.channel.local.LocalChannel) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) IOException(java.io.IOException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Example 27 with TooLongFrameException

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.TooLongFrameException in project vert.x by eclipse.

the class Http2Test method testClearTextUpgradeWithBodyTooLongFrameResponse.

@Test
public void testClearTextUpgradeWithBodyTooLongFrameResponse() throws Exception {
    server.close();
    Buffer buffer = TestUtils.randomBuffer(1024);
    server = vertx.createHttpServer().requestHandler(req -> {
        req.response().setChunked(true);
        vertx.setPeriodic(1, id -> {
            req.response().write(buffer);
        });
    });
    startServer(testAddress);
    client.close();
    client = vertx.createHttpClient(new HttpClientOptions().setProtocolVersion(HttpVersion.HTTP_2));
    client.request(new RequestOptions(requestOptions).setSsl(false)).onComplete(onSuccess(req -> {
        req.response(onFailure(err -> {
        }));
        req.setChunked(true);
        req.exceptionHandler(err -> {
            if (err instanceof TooLongFrameException) {
                testComplete();
            }
        });
        req.sendHead();
    }));
    await();
}
Also used : Buffer(io.vertx.core.buffer.Buffer) java.util(java.util) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) ConnectionBase(io.vertx.core.net.impl.ConnectionBase) Context(io.vertx.core.Context) PfxOptions(io.vertx.core.net.PfxOptions) BooleanSupplier(java.util.function.BooleanSupplier) OpenSSLEngineOptions(io.vertx.core.net.OpenSSLEngineOptions) ChannelPromise(io.netty.channel.ChannelPromise) TestUtils(io.vertx.test.core.TestUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DuplexChannel(io.netty.channel.socket.DuplexChannel) Http2ServerConnection(io.vertx.core.http.impl.Http2ServerConnection) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) Promise(io.vertx.core.Promise) TooLongFrameException(io.netty.handler.codec.TooLongFrameException) Test(org.junit.Test) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) Channel(io.netty.channel.Channel) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) Repeat(io.vertx.test.core.Repeat) Stream(java.util.stream.Stream) Buffer(io.vertx.core.buffer.Buffer) Ignore(org.junit.Ignore) AsyncTestBase(io.vertx.test.core.AsyncTestBase) Cert(io.vertx.test.tls.Cert) Http2CodecUtil(io.netty.handler.codec.http2.Http2CodecUtil) TooLongFrameException(io.netty.handler.codec.TooLongFrameException) Test(org.junit.Test)

Example 28 with TooLongFrameException

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.TooLongFrameException in project cxf by apache.

the class NettyHttpServletHandler method exceptionCaught.

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    LOG.log(Level.SEVERE, "UNEXPECTED_EXCEPCTION_IN_NETTY_SERVLET_HANDLER", cause);
    interceptOnRequestFailed(ctx, cause);
    Channel ch = ctx.channel();
    if (cause instanceof IllegalArgumentException) {
        ch.close();
    } else {
        if (cause instanceof TooLongFrameException) {
            sendError(ctx, HttpResponseStatus.BAD_REQUEST);
            return;
        }
        if (ch.isActive()) {
            sendError(ctx, HttpResponseStatus.INTERNAL_SERVER_ERROR);
        }
    }
    ctx.close();
}
Also used : TooLongFrameException(io.netty.handler.codec.TooLongFrameException) Channel(io.netty.channel.Channel)

Example 29 with TooLongFrameException

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.TooLongFrameException in project riposte by Nike-Inc.

the class BackstopperRiposteFrameworkErrorHandlerListener method shouldHandleException.

@Override
public ApiExceptionHandlerListenerResult shouldHandleException(Throwable ex) {
    if (ex instanceof CircuitBreakerException) {
        CircuitBreakerException cbe = ((CircuitBreakerException) ex);
        return ApiExceptionHandlerListenerResult.handleResponse(singletonError(getApiErrorForCircuitBreakerException(cbe)), singletonList(Pair.of("circuit_breaker_id", String.valueOf(cbe.circuitBreakerId))));
    }
    if (ex instanceof NonblockingEndpointCompletableFutureTimedOut) {
        return ApiExceptionHandlerListenerResult.handleResponse(singletonError(projectApiErrors.getTemporaryServiceProblemApiError()), singletonList(Pair.of("completable_future_timeout_value_millis", String.valueOf(((NonblockingEndpointCompletableFutureTimedOut) ex).timeoutValueMillis))));
    }
    if (ex instanceof DownstreamIdleChannelTimeoutException) {
        DownstreamIdleChannelTimeoutException idleEx = (DownstreamIdleChannelTimeoutException) ex;
        return ApiExceptionHandlerListenerResult.handleResponse(singletonError(projectApiErrors.getTemporaryServiceProblemApiError()), Arrays.asList(Pair.of("async_downstream_call_timeout_value_millis", String.valueOf(idleEx.timeoutValueMillis)), Pair.of("idle_channel_id", String.valueOf(idleEx.channelId))));
    }
    if (ex instanceof DownstreamChannelClosedUnexpectedlyException) {
        DownstreamChannelClosedUnexpectedlyException dsClosedEx = (DownstreamChannelClosedUnexpectedlyException) ex;
        return ApiExceptionHandlerListenerResult.handleResponse(singletonError(projectApiErrors.getTemporaryServiceProblemApiError()), singletonList(Pair.of("closed_channel_id", String.valueOf(dsClosedEx.channelId))));
    }
    if (ex instanceof DecoderException) {
        ApiError errorToUse = (ex instanceof TooLongFrameException) ? generateTooLongFrameApiError((TooLongFrameException) ex) : projectApiErrors.getMalformedRequestApiError();
        return ApiExceptionHandlerListenerResult.handleResponse(singletonError(errorToUse), withBaseExceptionMessage(ex, Pair.of("decoder_exception", "true")));
    }
    if (ex instanceof RequestTooBigException) {
        // TODO: RequestTooBigException should result in a 413 Payload Too Large error instead of generic 400 malformed request.
        // For now, we can at least let the caller know why it failed via error metadata.
        ApiError errorToUse = new ApiErrorWithMetadata(projectApiErrors.getMalformedRequestApiError(), Pair.of("cause", "The request exceeded the maximum payload size allowed"));
        return ApiExceptionHandlerListenerResult.handleResponse(singletonError(errorToUse), withBaseExceptionMessage(ex, Pair.of("decoder_exception", "true")));
    }
    if (ex instanceof HostnameResolutionException) {
        return ApiExceptionHandlerListenerResult.handleResponse(singletonError(projectApiErrors.getTemporaryServiceProblemApiError()), withBaseExceptionMessage(ex));
    }
    if (ex instanceof NativeIoExceptionWrapper) {
        return ApiExceptionHandlerListenerResult.handleResponse(singletonError(projectApiErrors.getTemporaryServiceProblemApiError()), singletonList(causeDetailsForLogs(ex)));
    }
    if (ex instanceof RequestContentDeserializationException) {
        RequestContentDeserializationException theEx = (RequestContentDeserializationException) ex;
        return ApiExceptionHandlerListenerResult.handleResponse(singletonError(projectApiErrors.getMalformedRequestApiError()), Arrays.asList(Pair.of("method", theEx.httpMethod), Pair.of("request_path", theEx.requestPath), Pair.of("desired_object_type", theEx.desiredObjectType.getType().toString()), causeDetailsForLogs(ex)));
    }
    if (ex instanceof PathNotFound404Exception) {
        return ApiExceptionHandlerListenerResult.handleResponse(singletonError(projectApiErrors.getNotFoundApiError()));
    }
    if (ex instanceof MethodNotAllowed405Exception) {
        MethodNotAllowed405Exception theEx = (MethodNotAllowed405Exception) ex;
        return ApiExceptionHandlerListenerResult.handleResponse(singletonError(projectApiErrors.getMethodNotAllowedApiError()), Arrays.asList(Pair.of("incoming_request_path", theEx.requestPath), Pair.of("incoming_request_method", theEx.requestMethod)));
    }
    if (ex instanceof Unauthorized401Exception) {
        Unauthorized401Exception theEx = (Unauthorized401Exception) ex;
        List<Pair<String, String>> extraDetails = withBaseExceptionMessage(ex, Pair.of("incoming_request_path", theEx.requestPath));
        extraDetails.addAll((theEx).extraDetailsForLogging);
        return ApiExceptionHandlerListenerResult.handleResponse(singletonError(projectApiErrors.getUnauthorizedApiError()), extraDetails);
    }
    if (ex instanceof Forbidden403Exception) {
        Forbidden403Exception theEx = (Forbidden403Exception) ex;
        List<Pair<String, String>> extraDetails = withBaseExceptionMessage(ex, Pair.of("incoming_request_path", theEx.requestPath));
        extraDetails.addAll((theEx).extraDetailsForLogging);
        return ApiExceptionHandlerListenerResult.handleResponse(singletonError(projectApiErrors.getForbiddenApiError()), extraDetails);
    }
    if (ex instanceof MissingRequiredContentException) {
        MissingRequiredContentException theEx = (MissingRequiredContentException) ex;
        return ApiExceptionHandlerListenerResult.handleResponse(singletonError(projectApiErrors.getMissingExpectedContentApiError()), Arrays.asList(Pair.of("incoming_request_path", theEx.path), Pair.of("incoming_request_method", theEx.method), Pair.of("endpoint_class_name", theEx.endpointClassName)));
    }
    if (ex instanceof MultipleMatchingEndpointsException) {
        MultipleMatchingEndpointsException theEx = (MultipleMatchingEndpointsException) ex;
        return ApiExceptionHandlerListenerResult.handleResponse(singletonError(projectApiErrors.getGenericServiceError()), Arrays.asList(Pair.of("incoming_request_path", theEx.requestPath), Pair.of("incoming_request_method", theEx.requestMethod), Pair.of("matching_endpoints", StringUtils.join(theEx.matchingEndpointsDetails, ","))));
    }
    if (ex instanceof PathParameterMatchingException) {
        PathParameterMatchingException theEx = (PathParameterMatchingException) ex;
        return ApiExceptionHandlerListenerResult.handleResponse(singletonError(projectApiErrors.getGenericServiceError()), Arrays.asList(Pair.of("path_template", theEx.pathTemplate), Pair.of("non_matching_uri_path", theEx.nonMatchingUriPath)));
    }
    if (ex instanceof InvalidCharsetInContentTypeHeaderException) {
        return ApiExceptionHandlerListenerResult.handleResponse(singletonError(projectApiErrors.getUnsupportedMediaTypeApiError()), singletonList(Pair.of("invalid_content_type_header", ((InvalidCharsetInContentTypeHeaderException) ex).invalidContentTypeHeader)));
    }
    if (ex instanceof TooManyOpenChannelsException) {
        TooManyOpenChannelsException theEx = (TooManyOpenChannelsException) ex;
        return ApiExceptionHandlerListenerResult.handleResponse(singletonError(projectApiErrors.getTemporaryServiceProblemApiError()), Arrays.asList(Pair.of("num_current_open_channels", String.valueOf(theEx.actualOpenChannelsCount)), Pair.of("max_open_channels_limit", String.valueOf(theEx.maxOpenChannelsLimit))));
    }
    if (ex instanceof IncompleteHttpCallTimeoutException) {
        IncompleteHttpCallTimeoutException theEx = (IncompleteHttpCallTimeoutException) ex;
        return ApiExceptionHandlerListenerResult.handleResponse(singletonError(new ApiErrorWithMetadata(projectApiErrors.getMalformedRequestApiError(), Pair.of("cause", "Unfinished/invalid HTTP request"))), withBaseExceptionMessage(ex, Pair.of("incomplete_http_call_timeout_millis", String.valueOf(theEx.timeoutMillis))));
    }
    if (ex instanceof InvalidHttpRequestException) {
        InvalidHttpRequestException theEx = (InvalidHttpRequestException) ex;
        Throwable cause = theEx.getCause();
        ApiError apiErrorToUse = (cause instanceof TooLongFrameException) ? generateTooLongFrameApiError((TooLongFrameException) cause) : new ApiErrorWithMetadata(projectApiErrors.getMalformedRequestApiError(), Pair.of("cause", "Invalid HTTP request"));
        return ApiExceptionHandlerListenerResult.handleResponse(singletonError(apiErrorToUse), withBaseExceptionMessage(ex, causeDetailsForLogs(theEx)));
    }
    return ApiExceptionHandlerListenerResult.ignoreResponse();
}
Also used : MissingRequiredContentException(com.nike.riposte.server.error.exception.MissingRequiredContentException) TooLongFrameException(io.netty.handler.codec.TooLongFrameException) HostnameResolutionException(com.nike.riposte.server.error.exception.HostnameResolutionException) Forbidden403Exception(com.nike.riposte.server.error.exception.Forbidden403Exception) TooManyOpenChannelsException(com.nike.riposte.server.error.exception.TooManyOpenChannelsException) IncompleteHttpCallTimeoutException(com.nike.riposte.server.error.exception.IncompleteHttpCallTimeoutException) RequestContentDeserializationException(com.nike.riposte.server.error.exception.RequestContentDeserializationException) MultipleMatchingEndpointsException(com.nike.riposte.server.error.exception.MultipleMatchingEndpointsException) ApiErrorWithMetadata(com.nike.backstopper.apierror.ApiErrorWithMetadata) PathParameterMatchingException(com.nike.riposte.server.error.exception.PathParameterMatchingException) Unauthorized401Exception(com.nike.riposte.server.error.exception.Unauthorized401Exception) Pair(com.nike.internal.util.Pair) NativeIoExceptionWrapper(com.nike.riposte.server.error.exception.NativeIoExceptionWrapper) RequestTooBigException(com.nike.riposte.server.error.exception.RequestTooBigException) InvalidCharsetInContentTypeHeaderException(com.nike.riposte.server.error.exception.InvalidCharsetInContentTypeHeaderException) PathNotFound404Exception(com.nike.riposte.server.error.exception.PathNotFound404Exception) InvalidHttpRequestException(com.nike.riposte.server.error.exception.InvalidHttpRequestException) CircuitBreakerException(com.nike.fastbreak.exception.CircuitBreakerException) NonblockingEndpointCompletableFutureTimedOut(com.nike.riposte.server.error.exception.NonblockingEndpointCompletableFutureTimedOut) DecoderException(io.netty.handler.codec.DecoderException) MethodNotAllowed405Exception(com.nike.riposte.server.error.exception.MethodNotAllowed405Exception) DownstreamChannelClosedUnexpectedlyException(com.nike.riposte.server.error.exception.DownstreamChannelClosedUnexpectedlyException) ApiError(com.nike.backstopper.apierror.ApiError) DownstreamIdleChannelTimeoutException(com.nike.riposte.server.error.exception.DownstreamIdleChannelTimeoutException)

Example 30 with TooLongFrameException

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.TooLongFrameException in project graylog2-server by Graylog2.

the class LenientDelimiterBasedFrameDecoderTest method testFailSlowTooLongFrameRecovery.

@Test
public void testFailSlowTooLongFrameRecovery() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new LenientDelimiterBasedFrameDecoder(1, true, false, false, Delimiters.nulDelimiter()));
    for (int i = 0; i < 2; i++) {
        ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 1, 2 }));
        try {
            assertTrue(ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0 })));
            fail(DecoderException.class.getSimpleName() + " must be raised.");
        } catch (TooLongFrameException e) {
        // Expected
        }
        ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'A', 0 }));
        ByteBuf buf = ch.readInbound();
        assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));
        buf.release();
    }
}
Also used : TooLongFrameException(io.netty.handler.codec.TooLongFrameException) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

TooLongFrameException (io.netty.handler.codec.TooLongFrameException)33 ByteBuf (io.netty.buffer.ByteBuf)15 Test (org.junit.Test)9 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)7 Channel (io.netty.channel.Channel)5 Buffer (io.vertx.core.buffer.Buffer)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 CorruptedFrameException (io.netty.handler.codec.CorruptedFrameException)4 TestUtils (io.vertx.test.core.TestUtils)4 Test (org.junit.jupiter.api.Test)4 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)3 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)3 ChannelHandler (io.netty.channel.ChannelHandler)2 EventLoop (io.netty.channel.EventLoop)2 DecoderException (io.netty.handler.codec.DecoderException)2 DelimiterBasedFrameDecoder (io.netty.handler.codec.DelimiterBasedFrameDecoder)2 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)2 HttpRequest (io.netty.handler.codec.http.HttpRequest)2 HttpResponse (io.netty.handler.codec.http.HttpResponse)2 io.vertx.core (io.vertx.core)2