Skip to content

Instantly share code, notes, and snippets.

@richdougherty
Last active November 23, 2017 20:48
Show Gist options
  • Save richdougherty/f485c07e72379b13694cbc0710a33f44 to your computer and use it in GitHub Desktop.
Save richdougherty/f485c07e72379b13694cbc0710a33f44 to your computer and use it in GitHub Desktop.
Play/Akka Coordinated Shutdown notes

Use CS to shut down Server and Application in Play

Changes to ApplicationLifecycle usage

  • Application components systems can continue to use ApplicationLifecycle
  • Can now also use CoordinatedShutdown if want richer API
    • Suggest that we don't change ApplicationLifecycle API to expose phases (yet)
  • Application can now create its own ApplicationLifecycle from the ActorSystem
    • Calls ApplicationLifecycle.stop() during a phase of CS
      • ApplicationLifecycle manages ordering (as suggested by Patrik)
    • Ensures that ActorSystem is created before anything other resources since they would depend on ApplicationLifecycle
    • Deprecate/remove ApplicationLifecycle from the ApplicationLoader.Context object
    • Server can now use the Application's ActorSystem's CS if they need to hook into Application shutdown
  • Change Application.stop() to call CoordinatedShutdown.run()
    • Maybe deprecate this method; remove it or replace it with something returning a Future

Server ActorSystem vs Application ActorSystem

  • need to keep Server/Application ActorSystem split in Dev mode since we don't have an alternative
  • In Prod/Test mode, the Server shares the ActorSystem with the Application - much simpler
  • server doesn't know which it is using for itself, just uses ActorSystem in ServerProvider.Context
  • server can register 'server/HTTP stack' stuff on the ActorSystem in ServerProvider.Context
  • server can register 'application' stuff on the ActorSystem in its Application's actorSystem

In Dev mode

  • Server now initiates Application shutdowns on reload by calling CS
  • Server needs to listen for Application-initiated shutdown and stop itself (new behaviour)
  • Suggest we don't worry too much for now about making phases work well across the two ActorSystems
    • e.g. timing Application shutdown vs socket close might be a bit random
    • can fix later if we want/care

Server backend specifics

  • AkkaHttpServer will shut down correctly since its HTTP stack is managed by the ActorSystem
  • NettyServer will need to explicitly hook into CS

AsyncHttpClient / Lagom's WebSocketClient

  • not sure if I understand the issues here?

Related project: simplify ActorSystem configuration code

  • Currently use a custom Configuration.load implementation which adds a new type of configuration file (reference-overrides.conf) — confusing!
  • Remove this and just write explicit configuration into ActorSystemProvider (we already do this for some stuff so it's a simplification)
  • think about Akka's exit-on-fatal-exception behaviour - not great in dev mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment