Skip to content
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

Introduce QuarkusBindException #23186

Merged
merged 1 commit into from
Jan 25, 2022
Merged

Introduce QuarkusBindException #23186

merged 1 commit into from
Jan 25, 2022

Conversation

geoand
Copy link
Contributor

@geoand geoand commented Jan 25, 2022

This exception is used to record the actual ports that
cause binding conflicts, thus allowing Quarkus to properly
inform the user of which port(s) caused conflicts
instead of guessing based on what the provided configuration.

Fixes: #22967

P.S. We could probably extend this even more in the future to provide the configuration property involved as well as the name of the "service" that tried to bind

This exception is used to record the actual ports that
cause binding conflicts, thus allowing Quarkus to properly
inform the user of which port(s) caused conflicts
instead of guessing based on what the provided configuration.

Fixes: quarkusio#22967
Copy link
Member

@cescoffier cescoffier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Note that every server (TCP server) could use this mechanism.

Throwable effectiveCause = event.cause();
if (effectiveCause instanceof BindException) {
if ((sslConfig == null) && (httpServerOptions != null)) {
effectiveCause = new QuarkusBindException(httpServerOptions.getPort());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would that work for negative ports (negative ports in Vert. x are random ports but all the verticles use the same port, unlike the port 0 which is random every time). I guess it's fine as it would indicate the negative port (like -1) and it's up to the user to check in the config which one it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, although this is an edge case which I am going to guess we won't see often, if ever :)
I think we would probably just handle it when printing the helper messages if the exception fails.

@geoand
Copy link
Contributor Author

geoand commented Jan 25, 2022

Note that every server (TCP server) could use this mechanism.

Yes absolutely. This can and should be extended further

@geoand geoand added the triage/waiting-for-ci Ready to merge when CI successfully finishes label Jan 25, 2022
Copy link
Member

@famod famod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Pretty much what I had in mind. 👍

Just one minor suggestion.


public QuarkusBindException(List<Integer> ports) {
if (ports.isEmpty()) {
throw new IllegalStateException("ports must not be empty");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, this is surely very unexpected, but wouldn't it be confusing for the user if he got that instead of e.g. Port ? seems to be in use by another process. (note the ? instead of the actual port)?
Might be better to add this as a suppressed exception?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that suppression doesn't work as the exception is not (fully) logged. So maybe just a warning?
IDK, really just a minor thing...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I added this check is that I wanted to guard against erroneous usage and not have to deal with empty ports when inspecting the exception

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that makes sense. But if it really kicks in and a user is faced with it, then it will be more puzzling.

I guess in the end it's more of a "quarkus developer" guard than anything that will ever pop up for an actual quarkus user.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, exactly! It's meant to be used by Quarkus developers (as it's part of the runtime package, so not meant to be part of the public API)

@gsmet
Copy link
Member

gsmet commented Jan 25, 2022

I won't backport this tonight, let's keep it for 2.7.1.Final.

@geoand geoand merged commit 7306607 into quarkusio:main Jan 25, 2022
@quarkus-bot quarkus-bot bot added this to the 2.8 - main milestone Jan 25, 2022
@quarkus-bot quarkus-bot bot removed the triage/waiting-for-ci Ready to merge when CI successfully finishes label Jan 25, 2022
@geoand geoand deleted the #22967 branch January 26, 2022 06:37
@gsmet gsmet modified the milestones: 2.8 - main, 2.7.1.Final Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

java.net.BindException on startup can result in spurious log messages
4 participants