Skip to content

Scope should be closed in the method of afterConcurrentHandlingStarted for async request #125

@lujiajing1126

Description

@lujiajing1126

For async requests, thread-bound resources should be cleaned in method afterConcurrentHandlingStarted of TracingHandlerInterceptor interceptor as is suggested in the document AsyncHandlerInterceptor.

In this case, I suppose active scope should be closed since this specific thread will be released back to the dispatch pool and possibly used later for subsequent requests. If the scope is not closed properly, the following requests cannot be traced.

Simply adding the following code at the end of afterConcurrentHandlingStarted makes it work,

Deque<Scope> scopeStack = getScopeStack(httpServletRequest);
if (scopeStack.size() > 0) {
    Scope scope = scopeStack.pop();
    scope.close();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions