Is it possible to get state when shiny onSessionEnded is not invoked?

We are trying to investigate why our applications are in this weird state. We have this code:

  session$onSessionEnded(function(){
    message("=== Disconnected! ===")
    .isConnected <<- FALSE
    if (currentEnv != "LOCAL"){
      quit( # stop the R process and restart container
        save = "no",
        status = .errorCode
      )
    }
  })

We have configuration using docker swarm when a single user has a unique docker container with the application, we do that because we have the state of the application in a global variable (it's probably not a good idea, but this is how the application is created).

And we sometimes get in the state where onSessionEnded is not executed at all, we're trying to investigate why.

Do you know any case when onSessionEnded may not be invoked? Does exception in an application may cause that the event doesn't fire? We have exception handling in our application, so sesionEnded is always executed. But I want to know if such a case can happen and where should I search for such an error. I'm not sure if we have an error in application that is not handled by our exception handler.