Hello!

At my company, we ran into some issues with non-correctly shutting down
apps in Docker containers.
We use the PeriodicExecutor for canary checks, and it tried to check the
app's health with no longer available services in between shutting down the
Registry and itself.

Thinking about it, we came to the conclusion that it doesn't make much
sense to shut down the PeriodicExecutor AFTER the Registry is gone.
Instead, it should stop itself beforehand with the help of
org.apache.tapestry5.ioc.services.RegistryShutdownHub.addRegistryWillShutdownListener(Runnable).

Are there any sensible scenarios for the PeriodicExecutor to run AFTER the
Registry is shut down and before the JVM terminates? Ok, you can shut down
the Registry manually, but I don't see that as a valid scenario to use the
current default behavior.

I suggest changing the PeriodicExecutor to use "willShutdown".
However, this is a breaking change, so I want to discuss this first, in
case I overlooked something.

Our current workaround is cancelling the job on willShutdown manually:

@Startup
public static void scheduleCanaryCheck(CanaryService canaryService,
                                       PeriodicExecutor executor,
                                       RegistryShutdownHub hub) {
    PeriodicJob job = executor.addJob(new
IntervalSchedule(Duration.ofMinutes(1).toMillis()),
                                      "canary-check",
                                      canaryService::check);
    hub.addRegistryWillShutdownListener(job::cancel);
}

Cheers!
Ben

Reply via email to