Search in sources :

Example 1 with OutboundException

use of com.netflix.zuul.exception.OutboundException in project zuul by Netflix.

the class OriginResponseReceiver method userEventTriggered.

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof CompleteEvent) {
        final CompleteReason reason = ((CompleteEvent) evt).getReason();
        if ((reason != SESSION_COMPLETE) && (edgeProxy != null)) {
            LOG.error("Origin request completed with reason other than COMPLETE: {}, {}", reason.name(), ChannelUtils.channelInfoForLogging(ctx.channel()));
            final ZuulException ze = new ZuulException("CompleteEvent", reason.name(), true);
            edgeProxy.errorFromOrigin(ze);
        }
        // See channelWrite() where these vars are first set onto the channel.
        try {
            super.userEventTriggered(ctx, evt);
        } finally {
            postCompleteHook(ctx, evt);
        }
    } else if (evt instanceof SslHandshakeCompletionEvent && !((SslHandshakeCompletionEvent) evt).isSuccess()) {
        Throwable cause = ((SslHandshakeCompletionEvent) evt).cause();
        ctx.channel().attr(SSL_HANDSHAKE_UNSUCCESS_FROM_ORIGIN_THROWABLE).set(cause);
    } else if (evt instanceof IdleStateEvent) {
        if (edgeProxy != null) {
            LOG.error("Origin request received IDLE event: {}", ChannelUtils.channelInfoForLogging(ctx.channel()));
            edgeProxy.errorFromOrigin(new OutboundException(READ_TIMEOUT, edgeProxy.getRequestAttempts()));
        }
        super.userEventTriggered(ctx, evt);
    } else {
        super.userEventTriggered(ctx, evt);
    }
}
Also used : IdleStateEvent(io.netty.handler.timeout.IdleStateEvent) SslHandshakeCompletionEvent(io.netty.handler.ssl.SslHandshakeCompletionEvent) CompleteEvent(com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteEvent) ZuulException(com.netflix.zuul.exception.ZuulException) CompleteReason(com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteReason) OutboundException(com.netflix.zuul.exception.OutboundException)

Example 2 with OutboundException

use of com.netflix.zuul.exception.OutboundException in project zuul by Netflix.

the class RequestAttempt method setException.

public void setException(Throwable t) {
    if (t != null) {
        if (t instanceof ReadTimeoutException) {
            error = "READ_TIMEOUT";
            exceptionType = t.getClass().getSimpleName();
        } else if (t instanceof OriginConnectException) {
            OriginConnectException oce = (OriginConnectException) t;
            if (oce.getErrorType() != null) {
                error = oce.getErrorType().toString();
            } else {
                error = "ORIGIN_CONNECT_ERROR";
            }
            final Throwable cause = t.getCause();
            if (cause != null) {
                exceptionType = t.getCause().getClass().getSimpleName();
            } else {
                exceptionType = t.getClass().getSimpleName();
            }
        } else if (t instanceof OutboundException) {
            OutboundException obe = (OutboundException) t;
            error = obe.getOutboundErrorType().toString();
            exceptionType = OutboundException.class.getSimpleName();
        } else if (t instanceof SSLHandshakeException) {
            error = t.getMessage();
            exceptionType = t.getClass().getSimpleName();
            cause = t.getCause().getMessage();
        } else {
            error = t.getMessage();
            exceptionType = t.getClass().getSimpleName();
            cause = Throwables.getStackTraceAsString(t);
        }
    }
}
Also used : ReadTimeoutException(io.netty.handler.timeout.ReadTimeoutException) OriginConnectException(com.netflix.zuul.netty.connectionpool.OriginConnectException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) OutboundException(com.netflix.zuul.exception.OutboundException)

Example 3 with OutboundException

use of com.netflix.zuul.exception.OutboundException in project zuul by Netflix.

the class ProxyEndpoint method handleOriginNonSuccessResponse.

protected void handleOriginNonSuccessResponse(final HttpResponse originResponse, DiscoveryResult chosenServer) {
    final int respStatus = originResponse.status().code();
    OutboundException obe;
    StatusCategory statusCategory;
    ClientException.ErrorType niwsErrorType;
    if (respStatus == 503) {
        // Treat 503 status from Origin similarly to connection failures, ie. we want to back off from this server
        statusCategory = FAILURE_ORIGIN_THROTTLED;
        niwsErrorType = ClientException.ErrorType.SERVER_THROTTLED;
        obe = new OutboundException(OutboundErrorType.SERVICE_UNAVAILABLE, requestAttempts);
        // TODO(carl-mastrangelo): pass in the clock for testing.
        origin.stats().lastThrottleEvent(ZonedDateTime.now());
        if (originConn != null) {
            originConn.getServer().incrementSuccessiveConnectionFailureCount();
            originConn.getServer().addToFailureCount();
            originConn.flagShouldClose();
        }
        if (currentRequestStat != null) {
            currentRequestStat.updateWithHttpStatusCode(respStatus);
            currentRequestStat.serviceUnavailable();
        }
    } else {
        statusCategory = FAILURE_ORIGIN;
        niwsErrorType = ClientException.ErrorType.GENERAL;
        obe = new OutboundException(OutboundErrorType.ERROR_STATUS_RESPONSE, requestAttempts);
        if (currentRequestStat != null) {
            currentRequestStat.updateWithHttpStatusCode(respStatus);
            currentRequestStat.generalError();
        }
    }
    obe.setStatusCode(respStatus);
    long duration = 0;
    if (currentRequestStat != null) {
        duration = currentRequestStat.duration();
    }
    if (currentRequestAttempt != null) {
        currentRequestAttempt.complete(respStatus, duration, obe);
    }
    // Flag this error with the ExecutionListener.
    origin.onRequestExceptionWithServer(zuulRequest, chosenServer, attemptNum, new ClientException(niwsErrorType));
    if ((isBelowRetryLimit()) && (isRetryable5xxResponse(zuulRequest, originResponse))) {
        LOG.debug("Retrying: status={}, attemptNum={}, maxRetries={}, startedSendingResponseToClient={}, hasCompleteBody={}, method={}", respStatus, attemptNum, origin.getMaxRetriesForRequest(context), startedSendingResponseToClient, zuulRequest.hasCompleteBody(), zuulRequest.getMethod());
        // detach from current origin.
        unlinkFromOrigin();
        // retry request with different origin
        passport.add(ORIGIN_RETRY_START);
        origin.adjustRetryPolicyIfNeeded(zuulRequest);
        proxyRequestToOrigin();
    } else {
        SessionContext zuulCtx = context;
        LOG.info("Sending error to client: status={}, attemptNum={}, maxRetries={}, startedSendingResponseToClient={}, hasCompleteBody={}, method={}", respStatus, attemptNum, origin.getMaxRetriesForRequest(zuulCtx), startedSendingResponseToClient, zuulRequest.hasCompleteBody(), zuulRequest.getMethod());
        // This is a final response after all retries that will go to the client
        zuulResponse = buildZuulHttpResponse(originResponse, statusCategory, obe);
        invokeNext(zuulResponse);
    }
}
Also used : StatusCategory(com.netflix.zuul.stats.status.StatusCategory) ZuulStatusCategory(com.netflix.zuul.stats.status.ZuulStatusCategory) SessionContext(com.netflix.zuul.context.SessionContext) ClientException(com.netflix.client.ClientException) OutboundException(com.netflix.zuul.exception.OutboundException)

Example 4 with OutboundException

use of com.netflix.zuul.exception.OutboundException in project zuul by Netflix.

the class NettyRequestAttemptFactory method mapNettyToOutboundException.

public OutboundException mapNettyToOutboundException(final Throwable t, final SessionContext context) {
    if (t instanceof OutboundException) {
        return (OutboundException) t;
    }
    // Map this throwable to zuul's OutboundException.
    final ErrorType errorType = mapNettyToOutboundErrorType(t);
    final RequestAttempts attempts = RequestAttempts.getFromSessionContext(context);
    if (errorType == OTHER) {
        return new OutboundException(errorType, attempts, t);
    }
    return new OutboundException(errorType, attempts);
}
Also used : ErrorType(com.netflix.zuul.exception.ErrorType) RequestAttempts(com.netflix.zuul.niws.RequestAttempts) OutboundException(com.netflix.zuul.exception.OutboundException)

Aggregations

OutboundException (com.netflix.zuul.exception.OutboundException)4 ClientException (com.netflix.client.ClientException)1 CompleteEvent (com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteEvent)1 CompleteReason (com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteReason)1 SessionContext (com.netflix.zuul.context.SessionContext)1 ErrorType (com.netflix.zuul.exception.ErrorType)1 ZuulException (com.netflix.zuul.exception.ZuulException)1 OriginConnectException (com.netflix.zuul.netty.connectionpool.OriginConnectException)1 RequestAttempts (com.netflix.zuul.niws.RequestAttempts)1 StatusCategory (com.netflix.zuul.stats.status.StatusCategory)1 ZuulStatusCategory (com.netflix.zuul.stats.status.ZuulStatusCategory)1 SslHandshakeCompletionEvent (io.netty.handler.ssl.SslHandshakeCompletionEvent)1 IdleStateEvent (io.netty.handler.timeout.IdleStateEvent)1 ReadTimeoutException (io.netty.handler.timeout.ReadTimeoutException)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)1