atomix / atomix

A Kubernetes toolkit for building distributed applications using cloud native principles

Home Page:https://atomix.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Automatically pick an ephemeral port when binding if none is provided

benji opened this issue · comments

Currently the user has to provide a specific port even when creating a client. The problem is that there is no reliable way to get an available port.

The tests are either:

  • hardcoding the ports - the test fails if another service is already using that port
  • using NettyMessagingServiceTest#findAvailablePort which is prone to race conditions

More generally when using Atomix clients it is desirable to have Atomix pick a port automatically instead of having to reserve one or resolve one dynamically.

It would be nice to let Netty /InetSocketAddress select an available ephemeral port.
It's possible to achieve this by using Address.fromAddress(0) or Address.fromAddress("host:0").

However there is currently no way to retrieve the port that has been chosen.
I would suggest to expose the resolved / bound port.

I've been experimenting with this in benji@6fe5f6b

Let me know if you think that could be a good change to the project.