I am following up on:
- https://cloud.google.com/blog/topics/developers-practitioners/graceful-shutdowns-cloud-run-deep-dive
- How to process SIGTERM signal gracefully in Java?
I have a CloudRun service which is doing some while
cycles which currently seem not to end after the CloudRun revision is replaced. I guess the CloudRun manager is waiting for the revision to gracefully end, which unfortunately does not happen.
I tried adding:
Runtime.getRuntime().addShutdownHook()
And end the loops with this listener. Unfortunately there are two issues:
- It is not possible to subscribe more shutdownHooks (each for one running loop) - getting errors of
Hook already running
. This is an implementation issue and I wonder if there is a different way to do this. - When I send the
SIGTERM
orSIGINT
to locally running service, it ends immediately and the shutdownHook is never called. This is a logical issue and I am not sure if this is the way CloudRun ends the revisions - it seems not, otherwise the loops would be immediately ended like on my localhost.