Search in sources :

Example 1 with ConsumerDisconnectedException

use of com.hotels.styx.client.netty.ConsumerDisconnectedException in project styx by ExpediaGroup.

the class HttpPipelineHandler method onResponseObservableError.

private State onResponseObservableError(ChannelHandlerContext ctx, Throwable cause, Object requestId) {
    if (!ongoingRequest.id().equals(requestId)) {
        return this.state();
    }
    metrics.proxy().server().requestsCancelled("responseError").increment();
    cancelSubscription();
    LOGGER.error(warningMessage(format("message='Error proxying request', requestId=%s cause=%s", requestId, cause)));
    if (cause instanceof ConsumerDisconnectedException) {
        return TERMINATED;
    }
    LiveHttpResponse response = exceptionToResponse(cause, ongoingRequest, originsHeaderName);
    responseWriterFactory.create(ctx).write(response).handle((ignore, exception) -> {
        if (exception != null) {
            httpErrorStatusListener.proxyErrorOccurred(cause);
            httpErrorStatusListener.proxyErrorOccurred(exception);
        } else {
            httpErrorStatusListener.proxyErrorOccurred(ongoingRequest, remoteAddress(ctx), response.status(), cause);
            statsSink.onComplete(ongoingRequest.id(), response.status().code());
            tracker.endTrack(ongoingRequest);
        }
        ctx.close();
        return null;
    }).handle((ignore, exception) -> {
        statsSink.onTerminate(ongoingRequest.id());
        tracker.endTrack(ongoingRequest);
        if (exception != null) {
            LOGGER.error(warningMessage("message='Error during write completion handling'"), exception);
        }
        return null;
    });
    return TERMINATED;
}
Also used : RequestTracker(com.hotels.styx.server.track.RequestTracker) LiveHttpResponse.response(com.hotels.styx.api.LiveHttpResponse.response) REQUEST_TIMEOUT(com.hotels.styx.api.HttpResponseStatus.REQUEST_TIMEOUT) ExceptionStatusMapperKt.buildExceptionStatusMapper(com.hotels.styx.server.netty.connectors.ExceptionStatusMapperKt.buildExceptionStatusMapper) QueueDrainingEventProcessor(com.hotels.styx.common.QueueDrainingEventProcessor) SENDING_RESPONSE(com.hotels.styx.server.netty.connectors.HttpPipelineHandler.State.SENDING_RESPONSE) TERMINATED(com.hotels.styx.server.netty.connectors.HttpPipelineHandler.State.TERMINATED) SERVICE_UNAVAILABLE(com.hotels.styx.api.HttpResponseStatus.SERVICE_UNAVAILABLE) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) BAD_REQUEST(com.hotels.styx.api.HttpResponseStatus.BAD_REQUEST) DecoderException(io.netty.handler.codec.DecoderException) HttpHandler(com.hotels.styx.api.HttpHandler) OriginUnreachableException(com.hotels.styx.api.exceptions.OriginUnreachableException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) REQUEST_ENTITY_TOO_LARGE(com.hotels.styx.api.HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE) HTTP_1_1(com.hotels.styx.api.HttpVersion.HTTP_1_1) TooLongFrameException(io.netty.handler.codec.TooLongFrameException) TransportLostException(com.hotels.styx.api.exceptions.TransportLostException) EMPTY_LAST_CONTENT(io.netty.handler.codec.http.LastHttpContent.EMPTY_LAST_CONTENT) InetSocketAddress(java.net.InetSocketAddress) ResponseTimeoutException(com.hotels.styx.api.exceptions.ResponseTimeoutException) StateMachine(com.hotels.styx.common.StateMachine) String.format(java.lang.String.format) BaseSubscriber(reactor.core.publisher.BaseSubscriber) CONTENT_LENGTH(com.hotels.styx.api.HttpHeaderNames.CONTENT_LENGTH) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) DO_NOT_MODIFY_RESPONSE(com.hotels.styx.server.netty.connectors.ResponseEnhancer.DO_NOT_MODIFY_RESPONSE) Optional(java.util.Optional) IGNORE_REQUEST_PROGRESS(com.hotels.styx.server.RequestProgressListener.IGNORE_REQUEST_PROGRESS) HttpErrorStatusListener(com.hotels.styx.server.HttpErrorStatusListener) RequestTimeoutException(com.hotels.styx.server.RequestTimeoutException) ACCEPTING_REQUESTS(com.hotels.styx.server.netty.connectors.HttpPipelineHandler.State.ACCEPTING_REQUESTS) WAITING_FOR_RESPONSE(com.hotels.styx.server.netty.connectors.HttpPipelineHandler.State.WAITING_FOR_RESPONSE) ResourceExhaustedException(com.hotels.styx.client.connectionpool.ResourceExhaustedException) CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) CompletableFuture(java.util.concurrent.CompletableFuture) HttpInterceptorContext(com.hotels.styx.server.HttpInterceptorContext) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) NoAvailableHostsException(com.hotels.styx.api.exceptions.NoAvailableHostsException) RequestProgressListener(com.hotels.styx.server.RequestProgressListener) CONNECTION(com.hotels.styx.api.HttpHeaderNames.CONNECTION) Objects.requireNonNull(java.util.Objects.requireNonNull) PluginException(com.hotels.styx.api.plugins.spi.PluginException) StyxClientException(com.hotels.styx.client.StyxClientException) NoServiceConfiguredException(com.hotels.styx.server.NoServiceConfiguredException) CLOSE(io.netty.channel.ChannelFutureListener.CLOSE) Eventual(com.hotels.styx.api.Eventual) ConsumerDisconnectedException(com.hotels.styx.client.netty.ConsumerDisconnectedException) Logger(org.slf4j.Logger) INTERNAL_SERVER_ERROR(com.hotels.styx.api.HttpResponseStatus.INTERNAL_SERVER_ERROR) IGNORE_ERROR_STATUS(com.hotels.styx.server.HttpErrorStatusListener.IGNORE_ERROR_STATUS) UTF_8(java.nio.charset.StandardCharsets.UTF_8) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) IOException(java.io.IOException) HttpResponseStatus(com.hotels.styx.api.HttpResponseStatus) Buffer(com.hotels.styx.api.Buffer) BadRequestException(com.hotels.styx.server.BadRequestException) ContentOverflowException(com.hotels.styx.api.ContentOverflowException) Flux(reactor.core.publisher.Flux) ByteStream(com.hotels.styx.api.ByteStream) FsmEventProcessor(com.hotels.styx.common.FsmEventProcessor) SimpleChannelInboundHandler(io.netty.channel.SimpleChannelInboundHandler) SENDING_RESPONSE_CLIENT_CLOSED(com.hotels.styx.server.netty.connectors.HttpPipelineHandler.State.SENDING_RESPONSE_CLIENT_CLOSED) Subscription(org.reactivestreams.Subscription) GATEWAY_TIMEOUT(com.hotels.styx.api.HttpResponseStatus.GATEWAY_TIMEOUT) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) StyxException(com.hotels.styx.api.exceptions.StyxException) CentralisedMetrics(com.hotels.styx.metrics.CentralisedMetrics) BAD_GATEWAY(com.hotels.styx.api.HttpResponseStatus.BAD_GATEWAY) Id(com.hotels.styx.api.Id) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) BadHttpResponseException(com.hotels.styx.client.BadHttpResponseException) ConsumerDisconnectedException(com.hotels.styx.client.netty.ConsumerDisconnectedException) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse)

Aggregations

Buffer (com.hotels.styx.api.Buffer)1 ByteStream (com.hotels.styx.api.ByteStream)1 ContentOverflowException (com.hotels.styx.api.ContentOverflowException)1 Eventual (com.hotels.styx.api.Eventual)1 HttpHandler (com.hotels.styx.api.HttpHandler)1 CONNECTION (com.hotels.styx.api.HttpHeaderNames.CONNECTION)1 CONTENT_LENGTH (com.hotels.styx.api.HttpHeaderNames.CONTENT_LENGTH)1 HttpResponseStatus (com.hotels.styx.api.HttpResponseStatus)1 BAD_GATEWAY (com.hotels.styx.api.HttpResponseStatus.BAD_GATEWAY)1 BAD_REQUEST (com.hotels.styx.api.HttpResponseStatus.BAD_REQUEST)1 GATEWAY_TIMEOUT (com.hotels.styx.api.HttpResponseStatus.GATEWAY_TIMEOUT)1 INTERNAL_SERVER_ERROR (com.hotels.styx.api.HttpResponseStatus.INTERNAL_SERVER_ERROR)1 REQUEST_ENTITY_TOO_LARGE (com.hotels.styx.api.HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE)1 REQUEST_TIMEOUT (com.hotels.styx.api.HttpResponseStatus.REQUEST_TIMEOUT)1 SERVICE_UNAVAILABLE (com.hotels.styx.api.HttpResponseStatus.SERVICE_UNAVAILABLE)1 HTTP_1_1 (com.hotels.styx.api.HttpVersion.HTTP_1_1)1 Id (com.hotels.styx.api.Id)1 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)1 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)1 LiveHttpResponse.response (com.hotels.styx.api.LiveHttpResponse.response)1