<font size=2 face="sans-serif">Thanks Martin, this is useful context<br>
<br>
Regards<br>
Benjamin</font>
<br>
<br>
<br>
<br><font size=1 color=#5f5f5f face="sans-serif">From: &nbsp; &nbsp; &nbsp;
&nbsp;</font><font size=1 face="sans-serif">Martin Kouba &lt;mkouba@redhat.com&gt;</font>
<br><font size=1 color=#5f5f5f face="sans-serif">To: &nbsp; &nbsp; &nbsp;
&nbsp;</font><font size=1 face="sans-serif">Benjamin Confino &lt;BENJAMIC@uk.ibm.com&gt;,
Matej Novotny &lt;manovotn@redhat.com&gt;</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Cc: &nbsp; &nbsp; &nbsp;
&nbsp;</font><font size=1 face="sans-serif">weld-dev@lists.jboss.org</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Date: &nbsp; &nbsp; &nbsp;
&nbsp;</font><font size=1 face="sans-serif">14/06/2018 10:28</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Subject: &nbsp; &nbsp;
&nbsp; &nbsp;</font><font size=1 face="sans-serif">Re: [weld-dev]
RquestScoped not active inside WeldInitialListener.requestDestroyed</font>
<br>
<hr noshade>
<br>
<br>
<br><tt><font size=2>Hello Benjamin,<br>
<br>
First of all, there is no guarantee that the request context is active
<br>
during @PreDestroy of a @SessionScoped bean (unlike @PostConstruct <br>
callback of any bean). And it is certainly not active when an http <br>
session times out. And that's the reason why <br>
UserSessionData.preDestroy(), which invokes @RequestScoped MyPrincipal
<br>
created by PrincipalProducer.produce(), is not correct.<br>
<br>
In this particular case, Weld follows the spec and destroys the session
<br>
context &quot;at the very end of the request in which invalidate() was
<br>
called&quot; [1]. So it's not destroyed immediately when invalidate() is
<br>
called. Furthermore, the order in which HTTP contexts are destroyed is
<br>
not defined. If needed, Weld first destroys conversation, then request
<br>
and finally session context. That's why the customer gets <br>
ContextNotActiveException.<br>
<br>
It's more like a chicken-egg problem. And since the session context has
<br>
&quot;wider&quot; scope I think it makes more sense to allow @RequestScoped
beans <br>
to access the session context in @PreDestroy callbacks and not vice versa.<br>
<br>
Martin<br>
<br>
[1]<br>
</font></tt><a href="http://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#session_context_ee"><tt><font size=2>http://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#session_context_ee</font></tt></a><tt><font size=2><br>
<br>
Dne 13.6.2018 v 16:23 Benjamin Confino napsal(a):<br>
&gt; Hello Matej<br>
&gt; <br>
&gt; I spoke to the customer, who kindly provided the following source
on <br>
&gt; github: </font></tt><a href="https://github.com/elexx/was9_bugs/tree/master/bug21"><tt><font size=2>https://github.com/elexx/was9_bugs/tree/master/bug21</font></tt></a><tt><font size=2><br>
&gt; <br>
&gt; It looks like the code is bound to a @PreDestroy method on the <br>
&gt; @SessionScoped annotated class UserSessionData. The PreDestroy fires
<br>
&gt; because session.invalidate() is called in LogoutServlet.<br>
&gt; <br>
&gt; Looking at <br>
&gt; </font></tt><a href="http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#request_contextit"><tt><font size=2>http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#request_contextit</font></tt></a><tt><font size=2>
<br>
&gt; doesn't seem like any of the four cases when the spec applies here.
We <br>
&gt; have left LogoutServlet's service() method before the new thread calls
<br>
&gt; the preDestroy method. So I think this is an application issue.<br>
&gt; <br>
&gt; Regards<br>
&gt; Benjamin<br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; From: Matej Novotny &lt;manovotn@redhat.com&gt;<br>
&gt; To: Benjamin Confino &lt;BENJAMIC@uk.ibm.com&gt;<br>
&gt; Cc: weld-dev@lists.jboss.org<br>
&gt; Date: 12/06/2018 13:17<br>
&gt; Subject: Re: [weld-dev] RquestScoped not active inside &nbsp; &nbsp;
&nbsp; <br>
&gt; &nbsp;&nbsp;WeldInitialListener.requestDestroyed<br>
&gt; ------------------------------------------------------------------------<br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; Hi,<br>
&gt; <br>
&gt; what does user code look like?<br>
&gt; Does he have an event listener?<br>
&gt; <br>
&gt; I'd say this depends on *precisely* what is his code bound to.<br>
&gt; At some point (after the invalidation), you should be getting <br>
&gt; ContextNotActiveException so I guess we need to know more about the
code <br>
&gt; to determine this.<br>
&gt; If the user has some code bound to &quot;generic&quot; servlet events,
it may well <br>
&gt; happen that they fire after CDI events.<br>
&gt; <br>
&gt; Matej<br>
&gt; <br>
&gt; ----- Original Message -----<br>
&gt; &nbsp;&gt; From: &quot;Benjamin Confino&quot; &lt;BENJAMIC@uk.ibm.com&gt;<br>
&gt; &nbsp;&gt; To: weld-dev@lists.jboss.org<br>
&gt; &nbsp;&gt; Sent: Monday, June 11, 2018 10:46:31 AM<br>
&gt; &nbsp;&gt; Subject: [weld-dev] RquestScoped not active inside &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; <br>
&gt; WeldInitialListener.requestDestroyed<br>
&gt; &nbsp;&gt;<br>
&gt; &nbsp;&gt; Hello.<br>
&gt; &nbsp;&gt;<br>
&gt; &nbsp;&gt; I have a customer who's getting ContextNotActiveExceptions
for the<br>
&gt; &nbsp;&gt; RequestScoped Context. This happens inside the invocation
of<br>
&gt; &nbsp;&gt; WeldInitialListener.requestDestroyed() after the customer's
application<br>
&gt; &nbsp;&gt; invalidated the session. DefaultLifecycleCallbackInvoker.invokeMethods<br>
&gt; &nbsp;&gt; invokes a method in application code, which calls a method
on a <br>
&gt; proxy, which<br>
&gt; &nbsp;&gt; results in weld attempting to get the context from the
BeanManager <br>
&gt; and the<br>
&gt; &nbsp;&gt; ContextNotActiveException.<br>
&gt; &nbsp;&gt;<br>
&gt; &nbsp;&gt; My question is simple. Is this an integration issue or
is this an <br>
&gt; application<br>
&gt; &nbsp;&gt; issue?<br>
&gt; &nbsp;&gt;<br>
&gt; &nbsp;&gt; Here is the stack:<br>
&gt; &nbsp;&gt;<br>
&gt; &nbsp;&gt; org.jboss.weld.context.ContextNotActiveException: WELD-001303:
No active<br>
&gt; &nbsp;&gt; contexts for scope type javax.enterprise.context.RequestScoped<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:731)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.getIfExists(ContextualInstanceStrategy.java:89)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; org.jboss.weld.bean.ContextualInstanceStrategy$CachingContextualInstanceStrategy.getIfExists(ContextualInstanceStrategy.java:164)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; org.jboss.weld.bean.ContextualInstance.getIfExists(ContextualInstance.java:63)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:83)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; org.jboss.weld.bean.proxy.ProxyMethodHandler.getInstance(ProxyMethodHandler.java:125)<br>
&gt; &nbsp;&gt; &lt;CustomerClass&gt;$$_WeldClientProxy.getUserId(Unknown
Source)<br>
&gt; &nbsp;&gt;<br>
&gt; &nbsp;&gt; &lt;Application Code&gt;<br>
&gt; &nbsp;&gt;<br>
&gt; &nbsp;&gt; at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:90)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)<br>
&gt; &nbsp;&gt; at java.lang.reflect.Method.invoke(Method.java:508)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.invokeMethods(DefaultLifecycleCallbackInvoker.java:97)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.preDestroy(DefaultLifecycleCallbackInvoker.java:90)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; org.jboss.weld.injection.producer.BasicInjectionTarget.preDestroy(BasicInjectionTarget.java:127)<br>
&gt; &nbsp;&gt; at org.jboss.weld.bean.ManagedBean.destroy(ManagedBean.java:191)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; org.jboss.weld.util.bean.IsolatedForwardingBean.destroy(IsolatedForwardingBean.java:50)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; org.jboss.weld.context.AbstractContext.destroyContextualInstance(AbstractContext.java:139)<br>
&gt; &nbsp;&gt; at <br>
&gt; org.jboss.weld.context.AbstractContext.destroy(AbstractContext.java:153)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; org.jboss.weld.context.AbstractManagedContext.deactivate(AbstractManagedContext.java:58)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; org.jboss.weld.context.AbstractBoundContext.deactivate(AbstractBoundContext.java:72)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; org.jboss.weld.servlet.HttpContextLifecycle.safelyDeactivate(HttpContextLifecycle.java:378)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; org.jboss.weld.servlet.HttpContextLifecycle.requestDestroyed(HttpContextLifecycle.java:311)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; org.jboss.weld.servlet.WeldInitialListener.requestDestroyed(WeldInitialListener.java:135)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; com.ibm.ws.webcontainer.managedobject.ManagedObjectListenerWrapper.requestDestroyed(ManagedObjectListenerWrapper.java:98)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; com.ibm.ws.webcontainer.webapp.WebApp.notifyServletRequestDestroyed(WebApp.java:2042)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; com.ibm.wsspi.webcontainer.collaborator.CollaboratorHelper.postInvokeCollaborators(CollaboratorHelper.java:532)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1282)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:82)<br>
&gt; &nbsp;&gt; at <br>
&gt; com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:963)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1817)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:382)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:465)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:532)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:318)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:88)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)<br>
&gt; &nbsp;&gt; at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)<br>
&gt; &nbsp;&gt; at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)<br>
&gt; &nbsp;&gt; at<br>
&gt; &nbsp;&gt; <br>
&gt; com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)<br>
&gt; &nbsp;&gt; at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)<br>
&gt; &nbsp;&gt; at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1909)<br>
&gt; &nbsp;&gt;<br>
&gt; &nbsp;&gt; Unless stated otherwise above:<br>
&gt; &nbsp;&gt; IBM United Kingdom Limited - Registered in England and
Wales with number<br>
&gt; &nbsp;&gt; 741598.<br>
&gt; &nbsp;&gt; Registered office: PO Box 41, North Harbour, Portsmouth,
Hampshire <br>
&gt; PO6 3AU<br>
&gt; &nbsp;&gt;<br>
&gt; &nbsp;&gt; _______________________________________________<br>
&gt; &nbsp;&gt; weld-dev mailing list<br>
&gt; &nbsp;&gt; weld-dev@lists.jboss.org<br>
&gt; &nbsp;&gt; </font></tt><a href="https://lists.jboss.org/mailman/listinfo/weld-dev"><tt><font size=2>https://lists.jboss.org/mailman/listinfo/weld-dev</font></tt></a><tt><font size=2><br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; Unless stated otherwise above:<br>
&gt; IBM United Kingdom Limited - Registered in England and Wales with
number <br>
&gt; 741598.<br>
&gt; Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire
PO6 3AU<br>
&gt; <br>
&gt; <br>
&gt; _______________________________________________<br>
&gt; weld-dev mailing list<br>
&gt; weld-dev@lists.jboss.org<br>
&gt; </font></tt><a href="https://lists.jboss.org/mailman/listinfo/weld-dev"><tt><font size=2>https://lists.jboss.org/mailman/listinfo/weld-dev</font></tt></a><tt><font size=2><br>
&gt; <br>
<br>
-- <br>
Martin Kouba<br>
Senior Software Engineer<br>
Red Hat, Czech Republic<br>
<br>
</font></tt>
<br>
<br><font size=2 face="sans-serif"><br>
Unless stated otherwise above:<br>
IBM United Kingdom Limited - Registered in England and Wales with number
741598. <br>
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6
3AU<br>
</font>