micronaut-core: EmbeddedServer java.net.BindException: Address already in use

Expected Behavior

Spinning up EmbeddedServer should never throw java.net.BindException: Address already in use

Actual Behaviour

Spinning up EmbeddedServer sometimes throws java.net.BindException: Address already in use.

My guess is that sometimes another process binds to the random port it has chosen before it has a chance to?

  • SocketUtils.findAvailableTcpPort() starts looking at port 1024 rather than 5000, increasing the probability of a clash with another container spun up during the test
  • In any case, random ports should be generated by binding to port 0 and accepting whatever the OS gives us- all other implementations are buggy. The port is only guaranteed to be free at the point SocketUtils checks, not by the time the server tries to listen.

Steps To Reproduce

No response

Environment Information

No response

Example Application

No response

Version

2.5.5

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (9 by maintainers)

Commits related to this issue

Most upvoted comments

One thought is to throw an exception in the getPort method before the server has started so if anyone came across this they would know what the issue is