typesafehub / akka-contrib-extra

ConductR Akka contributions
Other
9 stars 16 forks source link

Allow inspectionTick cancelling in overridden postStop method for NonBlockingProcess sub-classes #78

Open timaliberdov opened 6 years ago

timaliberdov commented 6 years ago

I'd like to be able to override the postStop method of NonBlockingProcess actor (in particular, to change the method of the process destruction or something like that, so I don't want to call the super.postStop in my new sub-class) and have the ability to cancel the inspectionTick Cancellable (since it's private for now). Therefore, I propose to make this val protected.

huntc commented 6 years ago

Thanks for this. Can you please expand on what your use case is?

timaliberdov commented 6 years ago

Yeah, sure. I need to stop process gracefully, and postStop uses process.destroy() with force=true. Unfortunately, this boolean parameter is not the only problem for me: NuProcess for Windows in destroy method calls native win32 function TerminateProcess regardless of the force argument value, so I want to achieve a different behavior by overriding postStop method.

huntc commented 6 years ago

You should be able to send a Destroy message to the actor, which should then send SIGTERM. PostStop should only occur after a period of time if SIGTERM failed. I’m unsure then why you need to override anything.

timaliberdov commented 6 years ago

As I said earlier, on Windows, the kernel32.dll function TerminateProcess is called in process.destroy() method, even if the force argument is false. And this function just terminates process forcibly, as if SIGKILL was sent. After such abnormal termination some of the processes (in my case this is InnoDB) can't recover properly on next startup. It would be nice if I could avoid calling the process.destroy() (and define something by myself to do graceful stop), at least for Windows users. I understand, that I can override the receive function for some messages and use default version for remaining types of messages. And it is OK, but if actor for some reason stops and postStop is called, I'd like to be able to use soft termination. The only thing that is bothering me is that I can't cancel the inspectionTick without using existing postStop and process.destroy(true) in it. Maybe we could make a new protected method that just cancels it instead of making the val protected. What do you think?

huntc commented 6 years ago

What could we do here:

https://github.com/typesafehub/akka-contrib-extra/blob/master/src/main/scala/akka/contrib/process/NonBlockingProcess.scala#L238

... to work-around the Windows behavior that you cite?

timaliberdov commented 6 years ago

I'm not 100% sure, but it seems like executing taskkill with /pid key and without /f helped. I don't think that it is a good idea to use this in a library code.
Also I found out that when, for example, we install our desktop version of an application on top of the running instance, windows service is being forcibly stopped => all actors are stopped too and we get force destroy in postStop. Is it possible to allow redefining the postStop with ability to cancel the inspectionTick (for example, when actor was stopped but application is still running, so that scheduled runnable won't be spamming Inspect messages to the stopped actor)?