[jboss-jira] [JBoss JIRA] (WFLY-11601) Weld vs Undertow bootstrap: Race condition

Stefan Gr (Jira) issues at jboss.org
Wed Jun 5 03:32:00 EDT 2019


    [ https://issues.jboss.org/browse/WFLY-11601?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13742573#comment-13742573 ] 

Stefan Gr commented on WFLY-11601:
----------------------------------

I had no time to investigate it myself but why is the {{BeanDeploymentModules.processBeanDeployments}} executed after the cleanup code? I've found this section in some [core documentation|https://github.com/weld/core/blob/603f95ab2a60bfbe962c4ec6ca84515585d2d686/docs/reference/src/main/asciidoc/ri-spi.asciidoc] which does not make sense to me, when weld/CDI is not even know all beans.
{noformat}
You must ensure that WeldInitialListener.contextInitialized() is called after beans are deployed is complete (Bootstrap.deployBeans() has been called).
{noformat}


But if it may break existing code if we move out that part, there might be another solution that requires changes in the CDI implementation:
* Set a flag which tells whether {{endInitialization was run}}
* In {{contextInitialized}} we check this flag and if it is true, we simply fire the event for {{@ApplicationScoped}}
* If the flag is false, we catch the ServletContext and fire the event as soon as {{endInitialization}} completes - just like it is done for non-web modules.

That requires some thread-safe code but should not break any code. The performance overhead shouln't be noticable because this only affects the initialization and not the runtime.
What do you think? Is there something I'm missing again?
Does it require a spec change?

> Weld vs Undertow bootstrap: Race condition
> ------------------------------------------
>
>                 Key: WFLY-11601
>                 URL: https://issues.jboss.org/browse/WFLY-11601
>             Project: WildFly
>          Issue Type: Bug
>          Components: CDI / Weld, Web (Undertow)
>    Affects Versions: 15.0.1.Final
>            Reporter: Stefan Gr
>            Assignee: Matěj Novotný
>            Priority: Major
>         Attachments: TestApp.zip, TestLib.zip, changes.diff, deploy-failed.txt, deploy-mixed-success.txt, deploy-success.txt, test-app-1.0.0.war, weld-core-impl-3.0.5.Final.jar, weld-core-impl-3.0.5.Final.jar
>
>
> WFLY-9732 / WFLY-10784 moves the completion of WELD from the WeldStartService to WeldStartCompetionService. This causes a race condition with the UndertowDeploymentService which executes the servlet listeners for context-initialized which again fires ApplicationScope-initialized events in CDI.
> You can find more in [WELD-2557|https://issues.jboss.org/browse/WELD-2557?focusedCommentId=13682848&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13682848].
> In short: WeldStartCompletionService and UndertowDeploymentService pushes the logic to the executor service. It may happen, that the logik of undertow runs before the weld completion. Events fired in the servlet listeners won't find all event observers.
> A possible solution would bo to set the WeldStartCompletionService as a dependency of the UndertowDeploymentService



--
This message was sent by Atlassian Jira
(v7.12.1#712002)



More information about the jboss-jira mailing list