-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assign random ports at configuration start (not later) #42986
Comments
Unfortunately, that's not possible. First it's not 0, but 0, -1, -2... The actual ports are provided by the operating system when we bind to the socket. We cannot do that before. Approaches that try "lease" ports at some point to use them later as kind of slow (you need to open a server, capture the port, close it) and you have no guarantee that the port will still be available when you start the actual servier. |
Not sure how it's actually a problem.
So that yes, but my guess is that you would be quite unlucky to have a port of the random range unavailable between reading the config and starting the server. https://unix.stackexchange.com/a/132524 seems to agree that it wouldn't be that much of a problem in practice. Sure it could maybe happen but I'm not really sure it's worth having the kind of hacks that we have at the moment. They are costing us too. I have no idea how slow it is to have a My problem with the current approach is that you cannot rely on Especially since it's often used in other configuration properties. |
Well, I got bitten by this multiple times. Maybe it's an OS issue (I also have issues on CI with this). Multiple times, the ports "leased" got re-assigned before being actually used, which creates a lot of flakiness and friction. |
Can we have a special config source or something that can retrieve free port using the (brittle) lease strategy? At least it's up to the user to use it and if it works everything is fine. It would be something like:
We do something simular for quarkus.uuid if I'm not mistaken. |
The annoying part is that users would have to move from setting How about we keep the socket open and release it when we know the consumer will need it? |
You would open, capture the port and release immediately (be aware that it's async for some OS), and then inject the captured port (hopping 1) the port has not been used in between, 2) the socket has released all the resources) But yes, they would have to use something different than |
We could manage it internally. We can create a |
Description
When we set a port configuration like
quarkus.http.port
to0
, we want Quarkus to assign a random port.The issue is the particular case of
quarkus.http.port
, the port generation and assignment are delegated to Vert.x. Why is this an issue?Because we rely on the Config system to lookup the real
quarkus.http.port
, we have to mutate the configuration after the configuration is already loaded. We useSystemProperties
, but this does not guarantee an override because there may be higher ordinal sources in the Config system that referencesquarkus.http.port
.Also, we need configuration to be loaded to start Vert.x. Once we load the configuration objects, we cache them for obvious reasons: for performance and to ensure everyone sees the exact copy of the configuration. This becomes another problem when we reference
${quarkus.http.port}
as an expression, which at the time of evaluation will be set to0
.We observed some of these issues in:
Implementation ideas
Ideally, we should move all random port assignments before loading the configuration.
The text was updated successfully, but these errors were encountered: