dokan-java icon indicating copy to clipboard operation
dokan-java copied to clipboard

Shutdown hooks - possible issues?

Open hrstoyanov opened this issue 4 years ago • 1 comments

The normal way to unmount a Dokan file system is to call the close() method, or implictly close it in a try/catch block Also, dokan file system will register a global VM shutdown hook that unmounts the file system if the JVM is killed or interrupted is some unexpected way.

The problem with the global shutdown is that DokanFIleSystem object can be part of a larger composition of objects where the order of shutting down resources can be very important and is determined by the owner object, for example:

NetworkReplicationServer implements AutoCloseable{
      private NewtorkAgent networkAgent:
      private DokanFIleSystem fileSystem;

      public NetworkReplicationServer(){
        ...
        Runtime.getRuntime().addShutdownHook(new Thread(this::close));
      }
      
      @Overrie
      public void close() throws Exception{
        CloseUtiils.cloaseAllInOrderSilently(networkAgent, fileSystem);
     }
}

My recommendation is to not register a global shutdown hook - this can always be done outside in the owning object. My current workaround for now is to override the mount() method and remove the shutdown registration...

hrstoyanov avatar Jul 27 '20 23:07 hrstoyanov

Another option is to add a boolaen parameter to the mount(...) method to control if shutdown hook is registered.

hrstoyanov avatar Aug 01 '20 06:08 hrstoyanov