Skip to content

Shutdown hooks - possible issues? #54

@hrstoyanov

Description

@hrstoyanov

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions