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

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 2.1.2.Final, 2.2.0.Alpha1
    • 2.1.1.Final
    • None
    • None
    • 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.

      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.

              rhn-engineering-jharting Jozef Hartinger
              smoyer64 Steve Moyer (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: