Both the CDI and the spec issue are actually reported by me, I was just surprised that I got no response there, but there has been quite some discussion about it here.
If it is acceptable to change CDI to use an interposed synchronisation, and that turns out to indeed resolve the problem, then that's the way to go.
However, its not just the CDI observers that suffer from this problem. In Narayana I've found a similar issue: the TransactionScopeCleanup synchronization. See my recent issue [WFLY-11450] Cannot get delegate of JMSContext during an beforeCompletion synch - JBoss Issue Tracker . Thats defenitely a class that lives here This is the call that causes WFLY-11450: narayana/TransactionScopeCleanup.java at master · jbosstm/narayana · GitHub
It just may be that there's a need for a public void registerSynchronization(AfterCompletionSynchronization sync) JTA spec change after all...
jwgmeligmeyling : I would try to elaborate first a bit on your query on CDI-724 / WELD-2444 from my point of view too. I understand your finding as a specific "corner" case that was not covered by CDI specification. I think there is no straightforward solution for the case.
As mentioned at WELD-2444 the WELD follows the specification. At the same time the JTA spec does not define some specific handling of this case. As tomjenkinson summarized I agree we need either changes in CDI spec to count with the case - that's what you started by CDI-724, or add a change in JTA to provide an API that WELD can use - per discussion with tomjenkinson and mmusgrov I think it makes the JTA interface unclean, or we can add Narayana specific "flag" (a system property) which can change the behaviour in way that could be desirable for you. That would be Narayana specific and the PR needs to be agreed to get into codebase.
The issue WFLY-11450 sounds it could be a error in the Narayana codebase. As you pointed the TransactionScopeCleanup does not use the synchronization registry which could be more appropriate. What do you think mmusgrov?
If I can see the right part of the specification it says
3.8 TransactionScoped Annotation
This association must be retained through any transaction suspend or resume calls as well as any Synchronization.beforeCompletion callbacks. Any Synchronization.afterCompletion methods will be invoked in an undefined context.
I would be happy for somone to prototype making the TSC use the TSR, however we should remember that a user asked for us to decouple it from JNDI: JBTM-3044. As such we can probably just instantiate a TSR within the TSC as we do in the CMRR:
narayana/CommitMarkableResourceRecord.java at master · jbosstm/narayana · GitHub