Reputation: 1
We are using org.apache.logging.log4j.ThreadContext
in a default scoped bean to store user properties in the span of the request. This is from the package : log4j-api-2.12.1.jar.
While making API request to another service, we use this bean to get these properties and add it as headers to org.springframework.http.HttpEntity
.
Now we started noticing weird behaviours where in we saw mismatch between the resource owner and resource on the downstream service. On adding logs, we found that these user properties have changed after adding them to headers and the API call has incorrect headers.
We are using an HandlerInterceptorAdapter
to set and cleaned up these properties.The preHandle()
is the only place where we are setting this property.
We have over defensively clean up the context, calling ThreadContext.remove
in prehandle(),posthandle() and afterCompletion()
.
Yet we still face this issue.
Spring version 2.2.0. Embedded Tomcat in a docker container.
Shouldn't thread context work similar to thread local? We can migrate to using ThreadLocal / Spring request scope, but I would love to figure out why this is happening in the first place.
Upvotes: 0
Views: 833