ScalatestRouteTest and Artery BindException

Hi all,

Using Akka version 2.6.3 and ScalatestRouteTest with the configuration of provider as cluster, we’re facing the issue that the artery default port ( 25520 ) is getting stuck, so in our next ScalatestRouteTest test defined in our scalaTest framework is failing because BindAddressException.

I also experiment the very same issue using TestKit , even terminating the actorSystem in my afterAll

  override def afterAll {

The error as I mention is a BindAddressException

  Cause: akka.remote.RemoteTransportException: Failed to bind TCP to [] due to: Bind failed because of [/] Address already in use: bind
  at akka.remote.artery.tcp.ArteryTcpTransport$anonfun$4.applyOrElse(ArteryTcpTransport.scala:269)
  at akka.remote.artery.tcp.ArteryTcpTransport$anonfun$4.applyOrElse(ArteryTcpTransport.scala:263)
  at scala.concurrent.Future.$anonfun$recoverWith$1(Future.scala:417)
  at scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:41)
  at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
  at akka.dispatch.BatchingExecutor$
  at akka.dispatch.ExecutionContexts$sameThreadExecutionContext$.unbatchedExecute(Future.scala:85)
  at akka.dispatch.BatchingExecutor.execute(BatchingExecutor.scala:122)
  at akka.dispatch.BatchingExecutor.execute$(BatchingExecutor.scala:116)

Any solution or workaround of this problem?.

Put provider as local, fix the problem, but we need to test some cluster scenarios, so is not a possible workaround.


Do you start more than one ActorSystem at s time? Logging at INFO level should clearly show when an ActorSystem is started an which port it is bound to.

Best for tests are to adjust the configuration of the akka.remote.artery.canonical.port=0 so that each ActorSystem binds to a free port.


No, as I mention this is happening in two separate test. One test is not cleaning properly the actorSystem ports bind, as artery, and then in the second test we have the bindException.

You can reproduce having two empty Test that extends scalaRouteTest, and you run all test using maven.

I have tried that without problems. ScalaRouteTest shuts down the ActorSystem at the end, before next test is started.

Maybe you run tests in parallel so that more than one test is running at the same time?

The problem is when the class doesn’t contain any tests. Then ScalaTest will not run afterAll and the ActorSystem is not shutdown.