Uploaded image for project: 'Karaf'
  1. Karaf
  2. KARAF-5315

Race condition during shutdown using SIGTERM

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.0.9
    • 4.0.10, 4.1.3, 4.2.0.M1
    • None
    • None
    • Linux using systemd

    Description

      During shutdown using SIGTERM there is a race condition.

      Error occurred shutting down framework: java.nio.channels.ClosedChannelException
      java.nio.channels.ClosedChannelException
               at sun.nio.ch.FileLockImpl.release(FileLockImpl.java:58)
               at org.apache.karaf.main.lock.SimpleFileLock.release(SimpleFileLock.java:78)
               at org.apache.karaf.main.Main.destroy(Main.java:642)
               at org.apache.karaf.main.Main.main(Main.java:188)
      Main process exited, code=exited, status=254
      

      There are several problems in the code of the Main class.

      1. The variable indicating the exit condition ( private boolean exiting; line 89) used in several threads is not volatile.
      2. The same is true for the lock (private Lock lock; line 87).
      3. The signal handler calls Main.this.destroy(); which is called by the main thread again after leaving function awaitShutdown() (line 581)

      Because the destroy() function releases the lock in the finally block the lock is released twice. The used implementation is the SimpleFileLock. In there the release() function is not synchronized. Since the channel of the file-lock is closed the second call will result in the exception.

      To get rid of the double release the SimpleFileLock.release() function should be synchronized. But I am not sure if the double call of the Main.destroy() function is an even bigger problem because all activators are stopped twice too.

                  while (timeout > 0) {
                      timeout -= step;
                      FrameworkEvent event = framework.waitForStop(step);
                      if (event.getType() != FrameworkEvent.WAIT_TIMEDOUT) {
                          activatorManager.stopKarafActivators();
                          return true;
                      }
                  }
      

      Maybe synchronizing the Main.destroy() function is a good idea too or find a different way to have the signal handler stopping the framework by just signaling the stop and waking up the main thread ....

      Attachments

        Issue Links

          Activity

            People

              jbonofre Jean-Baptiste Onofré
              martin.krueger Martin Krüger
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: