gracefulStop in cluster mode - "cannot enqueue after timer shutdown"

Hi ! Im seeing the following exception

java.lang.IllegalStateException: cannot enqueue after timer shutdown
	at akka.pattern.PromiseActorRef$.apply(AskSupport.scala:604)
	at akka.pattern.GracefulStopSupport.gracefulStop(GracefulStopSupport.scala:48)
	at akka.pattern.GracefulStopSupport.gracefulStop$(GracefulStopSupport.scala:46)
	at akka.pattern.package$.gracefulStop(package.scala:42)
	at akka.pattern.Patterns$.gracefulStop(Patterns.scala:238)
	at akka.pattern.Patterns.gracefulStop(Patterns.scala)

when performing gracefulStop on an actor in cluster mode:

Cluster cluster = Cluster.get(myActorSystem);
Patterns.gracefulStop(actorRef, Duration.create(1, TimeUnit.MINUTES))

Logs say

11:39:30 [INFO ] [a.c.Cluster(akka://my)                  ] [] - Cluster Node [akka.tcp://my@] - Marked address [akka.tcp://my@] as [Leaving]
11:39:31 [INFO ] [a.c.Cluster(akka://my)                  ] [] - Cluster Node [akka.tcp://my@] - Exiting (leader), starting coordinated shutdown
11:39:31 [INFO ] [a.c.Cluster(akka://my)                  ] [] - Cluster Node [akka.tcp://my@] - Leader is moving node [akka.tcp://my@] to [Exiting]
11:39:31 [INFO ] [a.c.Cluster(akka://my)                  ] [] - Cluster Node [akka.tcp://my@] - Exiting completed
11:39:31 [INFO ] [a.c.Cluster(akka://my)                  ] [] - Cluster Node [akka.tcp://my@] - Shutting down...
11:39:31 [INFO ] [a.c.Cluster(akka://my)                  ] [] - Cluster Node [akka.tcp://my@] - Successfully shut down
11:39:31 [INFO ] [emoteActorRefProvider$RemotingTerminator] [] - Shutting down remote daemon.
11:39:31 [INFO ] [emoteActorRefProvider$RemotingTerminator] [] - Remote daemon shut down; proceeding with flushing remote transports.
11:39:31 [INFO ] [a.r.Remoting                            ] [] - Remoting shut down
11:39:31 [INFO ] [emoteActorRefProvider$RemotingTerminator] [] - Remoting shut down.
11:39:31 [ERROR] [m.ShutdownOperation                     ] [qtp46494202-112] - Unable to execute operation class my.ShutdownOperation
java.lang.IllegalStateException: cannot enqueue after timer shutdown

Is this expected ? Akka 2.5.12. Without the “Thread.sleep(1000);” the gracefulStop seems to do ok (most of the time it seems).

The reason is that the actor system has been shutdown when you do the gracefulStop call. The actor is also stopped when the ActorSystem is shutdown.

@patriknw indeed, thx for your response.

What is the proper way to perform node graceful stop in cluster setup ?
Do i need to look into the “Coordinated Shutdown” extension or is there a simpler way ?

My naive solution was

  • leave cluster (=> other nodes stop sending me messages)
  • do graceful stop on actors (=> digest existing message queues)
  • shutdown actor system
    which is not working for the reasons you described.

Coordinated shutdown is the way to do it. You can register own tasks in the phases, for example stopping actors if they require some special graceful handling.

Coordinated shutdown is integrated with cluster leaving and will also shutdown the ActorSystem as the last task.

Thank you @patriknw for the useful hints, i really appreciate it. I will dive into coordinated shutdown. Thank you !