Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shutdown hooks - possible issues? #54

Open
hrstoyanov opened this issue Jul 27, 2020 · 1 comment · May be fixed by #55
Open

Shutdown hooks - possible issues? #54

hrstoyanov opened this issue Jul 27, 2020 · 1 comment · May be fixed by #55

Comments

@hrstoyanov
Copy link

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant