I have a game app, which is stateful, and it is deployed on Cloud Foundry. If I update the app, I need shutdown gracefully, i.e. the old version should not be stopped until all running games are finished.
According to the CF docs, when issuing cf stop
, the app is only given 10 seconds to shut down after the SIGTERM is sent, before the app gets killed using SIGKILL. This is not working in my case.
I thought about pushing state into sth like a DB or Redis, and then hot-swap the running games to the new app instance, but since I am heavily using Web Sockets, this seems to create more problems than it solves, cause it would also break the existing connections.
Another solution would be to not send a cf stop
, but instead add an operations endpoint to my app, like POST /api/admin/stop
, which makes the app stop accepting new games, and then shutdown itself after all running games have finished.
I third option could be to change the design entirely and use sth like WebRTC as protocol, which means the app will only server the static resources, but has no active role any more in running games, cause all clients then connect to each other directly instead of through the server. I am not experienced in WebRTC though and wonder whether the solution works reliably, e.g. if some users use a VPN.
Right now I am in favor of the second option. But is it supposed to be that way that a CF app can terminate itself? And if yes, how to do it cleanly?
Or are there any other options? What's the best solution?