Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response filter getting blocked for sometime intermittently #1710

Open
kark137 opened this issue Nov 28, 2023 · 0 comments
Open

Response filter getting blocked for sometime intermittently #1710

kark137 opened this issue Nov 28, 2023 · 0 comments

Comments

@kark137
Copy link

kark137 commented Nov 28, 2023

We are using zuul 2.1.6 and we got the response back form down stream API but it's getting blocked for some reason in the response/outbound filter sometimes (not all the time). It's happening intermittently and the CPU also not used much during these times.
What could be the root cause? Anyone faced a scenario like this?
Thank in advance for any suggestions..

Below is how the response filter looks like

@OverRide
HttpResponseMessage apply(HttpResponseMessage response) {
SessionContext context = response.getContext()

    if (SEND_RESPONSE_HEADERS.get()) {
        Headers headers = response.getHeaders()

        StatusCategory statusCategory = StatusCategoryUtils.getStatusCategory(response)
        if (statusCategory != null) {
            headers.set(X_ZUUL_STATUS, statusCategory.name())
        }

        RequestAttempts attempts = RequestAttempts.getFromSessionContext(response.getContext())
        String headerStr = ""
        if (attempts != null) {
            headerStr = attempts.toString()
        }
        headers.set(X_ZUUL_PROXY_ATTEMPTS, headerStr)

        headers.set(X_ZUUL, "zuul")
        headers.set(X_ZUUL_INSTANCE, System.getenv("EC2_INSTANCE_ID") ?: "unknown")
        headers.set(CONNECTION, KEEP_ALIVE)
        headers.set(X_ZUUL_FILTER_EXECUTION_STATUS, context.getFilterExecutionSummary().toString())
        headers.set(X_ORIGINATING_URL, response.getInboundRequest().reconstructURI())

        log.info("status:"+ attempts.get(0).getStatus()+" duration:"+ attempts.get(0).getDuration())

        if (response.getStatus() >= 400 && context.getError() != null) {
            Throwable error = context.getError()
            headers.set(X_ZUUL_ERROR_CAUSE,
                    error instanceof ZuulException ? ((ZuulException) error).getErrorCause() : "UNKNOWN_CAUSE")
        }

        if (response.getStatus() >= 400) {
            log.info("Passport: {}", CurrentPassport.fromSessionContext(context))
        }
    }

    if (context.debugRequest()) {
        Debug.getRequestDebug(context).forEach({ s -> log.info("REQ_DEBUG: " + s) })
        Debug.getRoutingDebug(context).forEach({ s -> log.info("ZUUL_DEBUG: " + s) })
    }

    return response
}

}

Let's say The status log which is after the headers.set got logged at 28-11-23 19:30:10 and the passport log, which is after few lines getting logged at 28-11-23 19:30:20. it is taking/blocked for 10 secs there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant