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 port1024
rather than5000
, 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 pointSocketUtils
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
- Bind to port zero get random port. Fixes #6085 — committed to micronaut-projects/micronaut-core by graemerocher 3 years ago
- Bind to port zero get random port. (#6128) * Bind to port zero get random port. Fixes #6085 * Cleanup * fix test — committed to micronaut-projects/micronaut-core by graemerocher 3 years ago
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