Hello.

We have a problem from a race condition in HttpContextLifecycle.requestInitialized()


The condition is as follows:

Thread one calls nestedInvocationGuard.set(new Counter());
Thread two calls Counter counter = nestedInvocationGuard.get();  Object marker = request.getAttribute(GUARD_PARAMETER_NAME);
Thread one has not yet called request.setAttribute(GUARD_PARAMETER_NAME, GUARD_PARAMETER_VALUE);

This will result in thread two having a counter but no marker, leading to ServletLogger.LOG.guardLeak(counter.value);

I believe this issue is known because of the following comment.

* This request has not been processed yet but the guard is set already. That indicates, that the guard leaked from a previous request
* processing - most likely the Servlet container did not invoke listener methods symmetrically. Log a warning and recover by
* re-initializing the guard

I am assuming that "symmetrically" is supposed to say "synchronised".

I have checked with the relevant team and there is no way we can call that method from inside a synchronised block. So I was hoping that you might have some alternatives?

I noticed that the file at
https://github.com/doctau/weld-core/blob/master/impl/src/main/java/org/jboss/weld/servlet/HttpContextLifecycle.java has been updated and no longer has that race condition? Do you think including that update resolve this issue? And if so which release will include that update.

Regards

Benjamin
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU