<font size=2 face="sans-serif">Hello Matej,<br>
<br>
Thank you for the fix, I tested it and it worked perfectly. I also created
a pull request to backport it to 2.4: </font><a href="https://github.com/weld/core/pull/1964"><font size=2 color=blue face="sans-serif">https://github.com/weld/core/pull/1964</font></a><font size=2 face="sans-serif">
which has also worked locally for me. <br>
<br>
My client is currently on CDI-1.2/Weld-2.4 so even if you don't want to
patch 2.4 at this point I may need to give them a one-of patch until they
are ready to move up to CDI-2.0; so if there's any fatal flaw in that backport
please let me know. &nbsp;<br>
<br>
Best 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">Matej Novotny &lt;manovotn@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;</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Cc: &nbsp; &nbsp; &nbsp;
&nbsp;</font><font size=1 face="sans-serif">Takayuki T Ishii &lt;EBB0F3L@jp.ibm.com&gt;,
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">31/01/2020 17:09</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Subject: &nbsp; &nbsp;
&nbsp; &nbsp;</font><font size=1 face="sans-serif">[EXTERNAL] Re:
[weld-dev] Question about conversations scope initilization &nbsp; &nbsp;
&nbsp; &nbsp;obeserver</font>
<br>
<hr noshade>
<br>
<br>
<br><tt><font size=2>Hello,<br>
<br>
so after some tedious debugging (and fair amount of time figuring out how
lazy conversation work in this case) I managed to get to the state you
were seeing.<br>
I think this is a bug - Weld doesn't fire @Initialized event in case where
user attempts to restore non-existing conversation.<br>
We correctly associate the request with new conversation before the exception
is thrown (which is what spec requires and tests) but we don't fire the
event.<br>
<br>
Issue is here - </font></tt><a href="https://issues.redhat.com/browse/WELD-2611"><tt><font size=2>https://issues.redhat.com/browse/WELD-2611</font></tt></a><tt><font size=2>
<br>
And I've proposed a fix here - </font></tt><a href="https://github.com/weld/core/pull/1962"><tt><font size=2>https://github.com/weld/core/pull/1962</font></tt></a><tt><font size=2>
<br>
<br>
If you could try that and tell me if it works, that would be great.<br>
Although I did use the same reproducer, so hopefully it'll work ;-)<br>
<br>
Regards and have a nice weekend!<br>
Matej<br>
<br>
----- Original Message -----<br>
&gt; From: &quot;Benjamin Confino&quot; &lt;BENJAMIC@uk.ibm.com&gt;<br>
&gt; To: &quot;Matej Novotny&quot; &lt;manovotn@redhat.com&gt;<br>
&gt; Cc: &quot;Takayuki T Ishii&quot; &lt;EBB0F3L@jp.ibm.com&gt;, weld-dev@lists.jboss.org<br>
&gt; Sent: Friday, January 31, 2020 1:20:50 AM<br>
&gt; Subject: RE: [weld-dev] Question about conversations scope initilization
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
obeserver<br>
&gt; <br>
&gt; Hello Matej<br>
&gt; <br>
&gt; After testing adding a call to `bean.getMsg` in the catch block, the<br>
&gt; behaviour is unchanged. I did some further digging and here's what
I<br>
&gt; found:<br>
&gt; <br>
&gt; On a fresh start of the sever I ping the url with a nonsense cid.<br>
&gt; <br>
&gt; ConversationBean will call conversation.begin() in the try block.
This<br>
&gt; triggers a codepath that leads to<br>
&gt; LazyHttpConversationContextImpl.checkContextInitialized() line 124,
that<br>
&gt; line will throw an exception. We go back out to ConversationBean where
the<br>
&gt; exception is caught. Then when the catch block calls conversation.begin()<br>
&gt; it will once again reach<br>
&gt; LazyHttpConversationContextImpl.checkContextInitialized() but this
time<br>
&gt; the if statement on line 121 returns true and so we never call<br>
&gt; initialize(). In both cases it is the same<br>
&gt; LazyHttpConversationContextImpl.<br>
&gt; <br>
&gt; I also put a breakpoint in the observer and pinged the URL without<br>
&gt; manually specificing a cid. From inside the observer method I can
see that<br>
&gt; LazyHttpConversationContextImpl.checkContextInitialized() line 128
is on<br>
&gt; the stack.<br>
&gt; <br>
&gt; <br>
&gt; So to summarise. When I call the url with a nonsense cdi: The try
block<br>
&gt; reaches checkContextInitialized and gets an exception on line 121.
Then<br>
&gt; the catch block reaches checkContextInitialized and does nothing because<br>
&gt; isInitialized() returns true. Thus neither attempt reaches line 128
and<br>
&gt; the observer method is never fied.<br>
&gt; <br>
&gt; This feels like a bug to me, not just because the observer isn't fired
but<br>
&gt; also because if the initilization method had an exception half way
though<br>
&gt; is it left in a good state? I don't know enough about these weld internals<br>
&gt; to check.<br>
&gt; <br>
&gt; It occurs to me that one possible fix is to swap line 89 with line
90 so<br>
&gt; that the exception takes place before initilized is set to true. Of
course<br>
&gt; that assumes that running initilized twice won't cause worse problems.<br>
&gt; <br>
&gt; What do you think? Is this a bug?<br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; From: &nbsp; Matej Novotny &lt;manovotn@redhat.com&gt;<br>
&gt; To: &nbsp; &nbsp; Benjamin Confino &lt;BENJAMIC@uk.ibm.com&gt;<br>
&gt; Cc: &nbsp; &nbsp; Takayuki T Ishii &lt;EBB0F3L@jp.ibm.com&gt;, weld-dev@lists.jboss.org<br>
&gt; Date: &nbsp; 28/01/2020 15:03<br>
&gt; Subject: &nbsp; &nbsp; &nbsp; &nbsp;[EXTERNAL] Re: [weld-dev] Question
about conversations<br>
&gt; scope initilization &nbsp; &nbsp; obeserver<br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; Hello,<br>
&gt; <br>
&gt; I think I know what is the &quot;problem&quot; here.<br>
&gt; Weld uses lazy conversation init - that means we don't activate context<br>
&gt; until you try and access a conversation scoped bean.<br>
&gt; <br>
&gt; Now, in your example, the ConversationBean tries to begin() a<br>
&gt; conversation, then calls the bean (which initializes the context and<br>
&gt; notifies the observer).<br>
&gt; However, in the situation where you try and pass in a non-existing<br>
&gt; conversation, the invocation to conversation.begin()[1] will blow
up with<br>
&gt; NonExistingConversationException and<br>
&gt; you will jump right into the catch block[2] where you begin a conversation<br>
&gt; with given ID, but you no longer invoke the bean, hence the context
won't<br>
&gt; get activated.<br>
&gt; Try adding the `bean.getMsg()` call to the catch block and see if
that<br>
&gt; helps.<br>
&gt; <br>
&gt; Note that CDI spec sets no requirements on how/when to activate the<br>
&gt; conversation context, so the lazy behaviour is compliant with spec
(and<br>
&gt; this is also why you saw no such test in TCKs).<br>
&gt; <br>
&gt; Regards<br>
&gt; Matej<br>
&gt; <br>
&gt; _________________________________________________________________________________<br>
&gt; [1]<br>
&gt; </font></tt><a href="https://gist.github.com/manovotn/b9e9fde25ab77b5e481d5b34edf02b0c#file-conversationbean-java-L4"><tt><font size=2>https://gist.github.com/manovotn/b9e9fde25ab77b5e481d5b34edf02b0c#file-conversationbean-java-L4</font></tt></a><tt><font size=2><br>
&gt; <br>
&gt; [2]<br>
&gt; </font></tt><a href="https://gist.github.com/manovotn/b9e9fde25ab77b5e481d5b34edf02b0c#file-conversationbean-java-L10-L16"><tt><font size=2>https://gist.github.com/manovotn/b9e9fde25ab77b5e481d5b34edf02b0c#file-conversationbean-java-L10-L16</font></tt></a><tt><font size=2><br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; ----- Original Message -----<br>
&gt; &gt; From: &quot;Benjamin Confino&quot; &lt;BENJAMIC@uk.ibm.com&gt;<br>
&gt; &gt; To: &quot;Matej Novotny&quot; &lt;manovotn@redhat.com&gt;<br>
&gt; &gt; Cc: &quot;Takayuki T Ishii&quot; &lt;EBB0F3L@jp.ibm.com&gt;,
weld-dev@lists.jboss.org<br>
&gt; &gt; Sent: Tuesday, January 28, 2020 12:06:14 PM<br>
&gt; &gt; Subject: RE: [weld-dev] Question about conversations scope initilization<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;obeserver<br>
&gt; &gt; <br>
&gt; &gt; Hello<br>
&gt; &gt; <br>
&gt; &gt; Thanks for the link. I had a look but I couldn't find any TCK
tests<br>
&gt; &gt; checking to see if an observer method will catch the new<br>
&gt; &gt; ConversationContext being created for the &quot;new transient
conversation&quot;.<br>
&gt; To<br>
&gt; &gt; check if a new conversation was activated I created an entirely
fresh<br>
&gt; &gt; server and ran the test application on it, the behaviour was
the same,<br>
&gt; the<br>
&gt; &gt; first url I pinged on this new server ended with &quot;cid=&quot;
and the observer<br>
&gt; &gt; didn't . Normally I've just been restarting the old server but<br>
&gt; restarting<br>
&gt; &gt; frequently.<br>
&gt; &gt; <br>
&gt; &gt; I've attached the recreate you requested. it consists of the
three<br>
&gt; classes<br>
&gt; &gt; attached to my previous email as well as a minimal html page.
To run it<br>
&gt; &gt; load it onto your server and ping<br>
&gt; &gt; <br>
&gt; </font></tt><a href="http://localhost:9080/ConversationContextTest/index.xhtml"><tt><font size=2>http://localhost:9080/ConversationContextTest/index.xhtml</font></tt></a><tt><font size=2><br>
&gt; &nbsp;to see the<br>
&gt; &gt; observer fire, and<br>
&gt; &gt; <br>
&gt; </font></tt><a href="http://localhost:9080/ConversationContextTest/index.xhtml?cid=99999"><tt><font size=2>http://localhost:9080/ConversationContextTest/index.xhtml?cid=99999</font></tt></a><tt><font size=2><br>
&gt; &nbsp;to see<br>
&gt; &gt; the observer fail to fire.<br>
&gt; &gt; <br>
&gt; &gt; Best regards<br>
&gt; &gt; Benjamin<br>
&gt; &gt; <br>
&gt; &gt; <br>
&gt; &gt; <br>
&gt; &gt; From: &nbsp; Matej Novotny &lt;manovotn@redhat.com&gt;<br>
&gt; &gt; To: &nbsp; &nbsp; Benjamin Confino &lt;BENJAMIC@uk.ibm.com&gt;<br>
&gt; &gt; Cc: &nbsp; &nbsp; weld-dev@lists.jboss.org, Takayuki T Ishii
&lt;EBB0F3L@jp.ibm.com&gt;<br>
&gt; &gt; Date: &nbsp; 27/01/2020 11:39<br>
&gt; &gt; Subject: &nbsp; &nbsp; &nbsp; &nbsp;[EXTERNAL] Re: [weld-dev]
Question about conversations<br>
&gt; &gt; scope initilization &nbsp; &nbsp; obeserver<br>
&gt; &gt; <br>
&gt; &gt; <br>
&gt; &gt; <br>
&gt; &gt; Hello,<br>
&gt; &gt; <br>
&gt; &gt; I'd start by pointing you to CDI TCK as that's a good starting
point to<br>
&gt; &gt; see what's covered.<br>
&gt; &gt; For your question, that would be this test -<br>
&gt; &gt; <br>
&gt; </font></tt><a href="https://github.com/eclipse-ee4j/cdi-tck/blob/master/impl/src/main/java/org/jboss/cdi/tck/tests/context/conversation/ClientConversationContextTest.java#L344-L349"><tt><font size=2>https://github.com/eclipse-ee4j/cdi-tck/blob/master/impl/src/main/java/org/jboss/cdi/tck/tests/context/conversation/ClientConversationContextTest.java#L344-L349</font></tt></a><tt><font size=2><br>
&gt; <br>
&gt; &gt; <br>
&gt; &gt; And possibly few more in the same test class.<br>
&gt; &gt; <br>
&gt; &gt; As for the linked classes - your `ConversationBean` is listening
for<br>
&gt; &gt; @Initialized event. Can you verify that a new conversation was
activated<br>
&gt; &gt; for your request instead of verifying that context was activated?<br>
&gt; &gt; E.g. check IDs or something along those lines? I suppose that
will hold<br>
&gt; &gt; true and in that case it works just as spec requires it to.<br>
&gt; &gt; From the top of my head I don't really know how we activate/deactivate<br>
&gt; &gt; ConversationContext, I'd need to dig that up, but looking at
CDI spec,<br>
&gt; it<br>
&gt; &gt; doesn't mandate that it is activated every time again and it
could<br>
&gt; already<br>
&gt; &gt; be active for given request.<br>
&gt; &gt; Plus from just the classes you linked, I cannot know if you test
this<br>
&gt; with<br>
&gt; &gt; no existing conversation or maybe with some long running one
before you<br>
&gt; &gt; try to send a request for non-existing one...and so on.<br>
&gt; &gt; So if the above doesn't is not enough to answer your question,
then<br>
&gt; we're<br>
&gt; &gt; going to need a complete reproducer so that we both talk about
the same<br>
&gt; &gt; scenario :)<br>
&gt; &gt; <br>
&gt; &gt; Matej<br>
&gt; &gt; <br>
&gt; &gt; ----- Original Message -----<br>
&gt; &gt; &gt; From: &quot;Benjamin Confino&quot; &lt;BENJAMIC@uk.ibm.com&gt;<br>
&gt; &gt; &gt; To: weld-dev@lists.jboss.org<br>
&gt; &gt; &gt; Cc: &quot;Takayuki T Ishii&quot; &lt;EBB0F3L@jp.ibm.com&gt;<br>
&gt; &gt; &gt; Sent: Monday, January 27, 2020 11:42:14 AM<br>
&gt; &gt; &gt; Subject: [weld-dev] Question about conversations scope initilization<br>
&gt; &gt; obeserver<br>
&gt; &gt; &gt; <br>
&gt; &gt; &gt; Hello<br>
&gt; &gt; &gt; <br>
&gt; &gt; &gt; I have a customer who's sent me a sample application, I
have attached<br>
&gt; &gt; the<br>
&gt; &gt; &gt; source to it below.<br>
&gt; &gt; &gt; <br>
&gt; &gt; &gt; When the customer visits index.xhtml they see the following
output:<br>
&gt; &gt; &gt; <br>
&gt; &gt; &gt; Conversation initialized.<br>
&gt; &gt; &gt; Conversation begun. </font></tt><a href="cid:1"><tt><font size=2>cid:1</font></tt></a><tt><font size=2>
, timeout:3600000<br>
&gt; &gt; &gt; Conversation destroyed. </font></tt><a href="cid:1"><tt><font size=2>cid:1</font></tt></a><tt><font size=2><br>
&gt; &gt; &gt; <br>
&gt; &gt; &gt; However when they append &quot;?cdi=&quot; or a non-existnant
identifier like<br>
&gt; &gt; &gt; &quot;?cdi=10000&quot; to the url they do not see &quot;Conversation
initialized.&quot;<br>
&gt; &gt; &gt; <br>
&gt; &gt; &gt; The CDI spec says that: If the propagated conversation cannot
be<br>
&gt; &gt; restored,<br>
&gt; &gt; &gt; the container must associate the request with a new transient<br>
&gt; &gt; conversation<br>
&gt; &gt; &gt; and throw an exception of type<br>
&gt; &gt; &gt; javax.enterprise.context.NonexistentConversationException.<br>
&gt; &gt; &gt; <br>
&gt; &gt; &gt; I'm wondering if this should apply here? Or would it only
apply if the<br>
&gt; &gt; cid<br>
&gt; &gt; &gt; pointed to an existing conversation that could not be restored?
And is<br>
&gt; &gt; there<br>
&gt; &gt; &gt; anything in the spec that covers this specific situation?<br>
&gt; &gt; &gt; <br>
&gt; &gt; &gt; Unless stated otherwise above:<br>
&gt; &gt; &gt; IBM United Kingdom Limited - Registered in England and Wales
with<br>
&gt; number<br>
&gt; &gt; &gt; 741598.<br>
&gt; &gt; &gt; Registered office: PO Box 41, North Harbour, Portsmouth,
Hampshire PO6<br>
&gt; &gt; 3AU<br>
&gt; &gt; &gt; <br>
&gt; &gt; &gt; _______________________________________________<br>
&gt; &gt; &gt; weld-dev mailing list<br>
&gt; &gt; &gt; weld-dev@lists.jboss.org<br>
&gt; &gt; &gt; <br>
&gt; &gt; <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>
&gt; &gt; <br>
&gt; &gt; <br>
&gt; &gt; <br>
&gt; &gt; <br>
&gt; &gt; <br>
&gt; &gt; Unless stated otherwise above:<br>
&gt; &gt; IBM United Kingdom Limited - Registered in England and Wales
with number<br>
&gt; &gt; 741598.<br>
&gt; &gt; Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire
PO6<br>
&gt; 3AU<br>
&gt; &gt; <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>
<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>