Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-1579

Weld-SE's shutdown hook fails to dispose of CDI managed objects

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 2.1.1.Final
    • Fix Version/s: 2.1.2.Final, 2.2.0.Alpha1
    • Component/s: None
    • Labels:
      None
    • Steps to Reproduce:
      Hide

      There are four ways to observe this problem:

      1) Bootstrap a Weld-SE container that starts a program using StartMain and press CTRL-C while the program executes.

      2) Send a SIGTERM to the process running the application's JVM.

      3) Include a System.exit(0) in the application.

      4) In an application without the @ApplicationScoped annotation, allow the application to exit by leaving the method that @Observes the ContainerInitialized event.

      Show
      There are four ways to observe this problem: 1) Bootstrap a Weld-SE container that starts a program using StartMain and press CTRL-C while the program executes. 2) Send a SIGTERM to the process running the application's JVM. 3) Include a System.exit(0) in the application. 4) In an application without the @ApplicationScoped annotation, allow the application to exit by leaving the method that @Observes the ContainerInitialized event.

      Description

      From the commit comment for pull request #444 (https://github.com/weld/core/pull/444)

      The shutdown hook needs to be registered with the JVM before the Weld container is initialized. Without the shutdown hook, the following problems occur (or can occur):

      • System.exit(0) will terminate the program without any @PreDestroy or @Disposes methods being called.
      • CTRL-C will terminate the program without any @PreDestroy or @Disposes methods being called.
      • SIGTERM will terminate the program without any @PreDestroy or @Disposes methods being called.
      • Normal completion of methods that @Observes the ContainerInitialized events (effectively the program's entry points) will not call @PreDestroy or @Disposes methods unless they're @ApplicationScoped.
      • Since calling addShutdownHook() is not permitted once the JVM has started the shutdown process, multi-threaded applications can allow the main thread to return to StartMain while the JVM is still running. Executing addShutdownHook() in this instance will throw an IllegalStateException.

      The problem described in this thread (https://community.jboss.org/thread/180032?start=0&tstart=0) may be related.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                jharting Jozef Hartinger
                Reporter:
                smoyer64 Steve Moyer
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: