1

I am trying to run 2 different akka grpc servers however they cannot run concurrently. I try binding one server on localhost port 8080 and the other one on localhost port 8090. Separate they run fine but when I try to run them together I get the following error:

[ERROR] [05/13/2021 11:14:30.862] [Server-akka.actor.internal-dispatcher-6] [akka://Server/system/IO-TCP/selectors/$a/0] Bind failed for TCP channel on endpoint [/192.168.1.10:25520]
java.net.BindException: [/192.168.1.10:25520] Address already in use: bind

Here is the code were I try to create them:

 val service: HttpRequest => Future[HttpResponse] =
    StoreServiceHandler(new StoreImpl())

  // Bind service handler servers to localhost:8080/8081
  val binding = Http().newServerAt("127.0.0.1", 8080).bind(service)

  // report successful binding
  binding.foreach { binding => println(s"gRPC server bound to: ${binding.localAddress}") 

and

val service: HttpRequest => Future[HttpResponse] =
  CommunicationChannelHandler(new CommunicationChannelImpl())

// Bind service handler servers to localhost:8080/8081
val binding = Http().newServerAt("127.0.0.1", 8090).bind(service)

// report successful binding
binding.foreach { binding => println(s"gRPC server bound to: ${binding.localAddress.getPort}") }

Note: the print statement returns the right ports so I do not understand why they cannot run together/ why they both try to use port 2552.

Dirac
  • 25
  • 5
  • Did you find the reason they were both using the port 2552? Were you able to solve the problem? – zmerr Jun 11 '21 at 18:29
  • Akka’s cluster examples have the port `2552` configured as the port for the communication of the nodes of the cluster. it should be in the `application.conf`. This is for getting the cluster to work and is separate from the port on which you `grpc` service on the same node would be running which would be used for communication by the clients. When you run the two instances, both of them try to bind on 2552. You need to configure one of them to bind to some other node such as `2553` for the internal communication amongst cluster nodes instead. – zmerr Jun 11 '21 at 18:52
  • the configuration might as well have been set programmatically. – zmerr Jun 11 '21 at 18:53

1 Answers1

1

I would rather use the localhost notation instead of 127.0.0.1.

From the official documentation:

val bindingFuture = Http().newServerAt("localhost", 8080).bind(route)

The difference between localhost, 0.0.0.0, and 127.0.0.1 addresses is explained in more details in this superuser question.

Antoine
  • 1,393
  • 4
  • 20
  • 26