-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
In WSL dev/test mode print localhost instead of 0.0.0.0 in serverListeningMessage #40700
In WSL dev/test mode print localhost instead of 0.0.0.0 in serverListeningMessage #40700
Conversation
@gsmet From a new branch because the last PR was from my main branch... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Indeed, always push your PR from a feature branch.
This looks mostly good to me except for one concern, serious in one case and more for consistency in the other.
Could you have a look?
@@ -24,7 +24,7 @@ public boolean isDevOrTest() { | |||
* Returns true if the current launch is the server side of remote dev. | |||
*/ | |||
public static boolean isRemoteDev() { | |||
return (current() == DEVELOPMENT) && "true".equals(System.getenv("QUARKUS_LAUNCH_DEVMODE")); | |||
return (current() == DEVELOPMENT) && System.getenv("QUARKUS_LAUNCH_DEVMODE").equals("true"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't change this. It looks odd but this is actually the safer pattern as it works even if System.getenv("QUARKUS_LAUNCH_DEVMODE")
is null
. Your new pattern will fail with a NPE in this case.
You know it once you got bitten by it :).
* Do not use this during the actual configuration, use options.getHost() there directly instead. | ||
*/ | ||
private static String getDeveloperFriendlyHostName(HttpServerOptions options) { | ||
return (isWSL() && LaunchMode.current().isDevOrTest() && options.getHost().equals("0.0.0.0")) ? "localhost" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think getHost()
can ever return null
but I would use the safe pattern here too and have 0.0.0.0
first.
Hey @tamaro-skaljic , do you wish to finalize this PR or do you want me to finalize it? |
The previous commit was actually changing the logic for the default case.
1d5003c
to
64bf132
Compare
if (builder.getDefaultValues().get(QUARKUS_HTTP_HOST) == null) { | ||
// Sets the default host config value, depending on the launch mode | ||
if (LaunchMode.isRemoteDev()) { | ||
// in remote-dev mode we need to listen on all interfaces | ||
// in remote dev mode, we want to listen on all interfaces | ||
// to make sure the application is accessible | ||
builder.withDefaultValue(QUARKUS_HTTP_HOST, ALL_INTERFACES); | ||
} else if (LaunchMode.current().isDevOrTest()) { | ||
if (!isWSL()) { | ||
// in dev mode, we want to listen only on localhost | ||
// to make sure the app is not accessible from the outside | ||
builder.withDefaultValue(QUARKUS_HTTP_HOST, LOCALHOST); | ||
} else { | ||
// except when using WSL, as otherwise the app wouldn't be accessible from the host | ||
builder.withDefaultValue(QUARKUS_HTTP_HOST, ALL_INTERFACES); | ||
} | ||
} else { | ||
// In dev-mode we want to only listen on localhost so others on the network cannot connect to the application. | ||
// However, in WSL this would result in the application not being accessible, | ||
// so in that case, we launch it on all interfaces. | ||
builder.withDefaultValue(QUARKUS_HTTP_HOST, | ||
(LaunchMode.current().isDevOrTest() && !isWSL()) ? "localhost" : ALL_INTERFACES); | ||
// in all the other cases, we make sure the app is accessible on all the interfaces by default | ||
builder.withDefaultValue(QUARKUS_HTTP_HOST, ALL_INTERFACES); | ||
} | ||
} | ||
return builder; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dmlloyd could you have a look at this change as it could have some security consequences?
I adjusted it because the previous commit by the OP actually changed the default value and I wanted to make it extra clear (even if a bit more verbose).
The new version should be exactly as what we have in main
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Status for workflow
|
@tamaro-skaljic thanks for raising this and working on a patch! |
Like #40497 but with requested changes #40497 (review).