Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.0.4] ServletContextListener.contextInitialized invoked multiple times #24415

Closed
ctabin opened this issue May 13, 2023 · 3 comments · Fixed by #24570
Closed

[7.0.4] ServletContextListener.contextInitialized invoked multiple times #24415

ctabin opened this issue May 13, 2023 · 3 comments · Fixed by #24570

Comments

@ctabin
Copy link
Contributor

ctabin commented May 13, 2023

Hello,

In the context of a WAR, we have a simple ServletContextListener to initialize/shutdown our application when it is deployed. We only have one single servlet, so we expect the methods contextInitialized and contextDestroyed to be invoked only once when the application is deployed and undeployed.

Here is some piece of code:

@WebListener
public class DispatcherListener implements ServletContextListener {
    private static final Logger LOG = Logger.getLogger(DispatcherListener.class.getName());

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        log.log(Level.SEVERE, "Listener initialized");
    }
}
@WebServlet(urlPatterns="/*", loadOnStartup=1)
public class DispatcherServlet extends HttpServlet {
   //nothing special here
}

Here the log output after the deployment:

May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized
SEVERE: Listener initialized
May 13, 2023 2:01:56 PM my.application.DispatcherListener contextInitialized

In Payara 6.2023.4, the log does only appear once, which is (in my sense) the expected behavior.

Environment:

  • JDK17
  • glassfish-embedded-all 7.0.4
  • Linux Debian
@OndroMih
Copy link
Contributor

OndroMih commented Jun 3, 2023

Thanks for reporting this. It happens also in Embedded 7.0.5

The reason is that in WebArchivist.postAnnotationProcess(), while GlassFish server processes JARs inside the WAR with a separate scanner, Embedded processes them always with the same scanner. Therefore it will discover each annotation in the WAR file multiple times, each time for each JAR file in the WAR.

@ctabin
Copy link
Contributor Author

ctabin commented Jun 4, 2023

Hi @OndroMih, thanks for coming back. Indeed it seems linked to libraries included in standalone war. You'll find a testcase here.

@OndroMih
Copy link
Contributor

OndroMih commented Sep 3, 2023

It looks like this got broken with #24082, which simplified handling of ScatteredArchive for GlassFish Embedded too much. The new ScatteredWebArchivist.EmbeddedWebScanner is called for the whole WAR and also for each JAR, as before, but after #24082 it reports the classes in the classes directory even when called for nested JARs.

#24570 should fix this, but I raised is as draft for now because there are still some things to do (e.g. tests).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants