Search code examples
network-programmingakkaakka-remote-actor

Akka remoting binds to hostname instead of bind-hostname


Context

I am trying to run an akka application on a node and make it work with other nodes using akka remoting capabilities.

My node has an IP address, 10.254.55.10, and there is an external IP, 10.10.10.44, redirecting to the former. This external IP is the one on which I want other nodes to contact me.

Extract from my akka app config:

  akka {
            remote {
                    netty.tcp {
                            hostname = "10.10.10.44"
                            port = 2551

                            bind-hostname = "10.254.55.10"
                            bind-port = 2551
                    }
            }
  }

I know everything works fine on the network side, because when I listen on my IP with netcat, I can send messages to myself via telnet using the external IP.

In other words, when running these two commands in separate shells:

$ nc -l 10.254.55.10 2551

$ telnet 10.10.10.44 2551

I'm able to communicate with myself, proving the network redirection works fine between the two IPs.

Problem

When launching the application, it crashes with a bind error:

INFO Remoting - Starting remoting
ERROR a.r.t.n.NettyTransport - failed to bind to /10.10.10.44:2551, shutting down Netty transport
Exception in thread "main" java.lang.ExceptionInInitializerError
[...]
Caused by: org.jboss.netty.channel.ChannelException: Failed to bind to: /10.10.10.44:2551
[...]
Caused by: java.net.BindException: Cannot assign requested address
[...]
INFO a.r.RemoteActorRefProvider$RemotingTerminator - Shutting down remote daemon.

I assume what makes it crash is that it tries to bind to an IP that is not present locally (i.e. 10.10.10.44). But what I don't understand in first place is why akka is even trying to bind to 10.10.10.44, since it is not my bind-hostname (which is 10.254.55.10). This doc page seemed pretty clear to me on that matter, yet it doesn't work...


Solution

  • The project I was working with was based on akka 2.3.4, in which bind-hostname and bind-port configuration keys do not exist. I upgraded to latest version at the time, akka 2.4.1, and it solved the problem.