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

Print localhost instead of 0.0.0.0 in serverListeningMessage when in dev/test mode under WSL #40497

Closed
wants to merge 0 commits into from

Conversation

tamaro-skaljic
Copy link
Contributor

Is related to #22956 and #40463.

Copy link
Member

@gsmet gsmet left a comment

Choose a reason for hiding this comment

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

Thanks for opening the PR. I'm not sure this patch is quite right but it raises interesting questions.

Let's wait for @radcortez and @cescoffier to chime in.

*/
private boolean isWSL() {
var sysEnv = System.getenv();
return sysEnv.containsKey("IS_WSL") || sysEnv.containsKey("WSL_DISTRO_NAME");
Copy link
Member

Choose a reason for hiding this comment

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

@dmlloyd @radcortez I wonder if it's something we should include in SmallRye Common (OS maybe?)?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we can move it there.

Copy link
Member

Choose a reason for hiding this comment

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

A safer check is to look for Microsoft in /proc/version based on some quick research.

Copy link
Member

Choose a reason for hiding this comment

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

@@ -45,19 +45,11 @@ public String getValue(String propertyName) {
// 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.
return (LaunchMode.current().isDevOrTest() && !isWSL()) ? "localhost" : ALL_INTERFACES;
return (LaunchMode.current().isDevOrTest() && !LaunchMode.isWSL()) ? "localhost" : ALL_INTERFACES;
Copy link
Member

Choose a reason for hiding this comment

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

Also not related to your patch but it seems weird we only override quarkus.http.host as there are other problematic values as seen in the VertxHttpRecorder extract below.

I think it makes sense to default to 0.0.0.0 in the WSL Linux case for most cases. WDYT @cescoffier @radcortez ?

Copy link
Member

Choose a reason for hiding this comment

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

I believe so.

@gsmet
Copy link
Member

gsmet commented May 10, 2024

@tamaro-skaljic could you clarify what you're trying to do here?

My understanding is that in the case of WSL, we want to listen on all interfaces for things to work. What you are reporting is that with WSL, you cannot access the Quarkus app with 0.0.0.0? But listening to 0.0.0.0 at the Quarkus level and accessing your app in your browser with localhost works?

@tamaro-skaljic
Copy link
Contributor Author

tamaro-skaljic commented May 10, 2024

@tamaro-skaljic could you clarify what you're trying to do here?

@gsmet Of course!

I created this issue here #40463 which was fixed through #40467.

But for me, the issue was more a matter of (practical) developer experience than documentation (=theoretical developer experience).

When starting a quarkus application, it displays the URL to access the application in the start up message. As a developer that's a nice feature because you can click on the URL in your Terminal and it's opened in your default browser.

Unfortunately because of HttpHostConfigSource.java#L46 the host isn't set to localhost under WSL in dev/test mode. This results in the following URL displayed:
image
Clicking on this URL will result in an ERR_ADDRESS_INVALID error in the browser.
Quarkus may be listening on all interfaces, but in the browser it is still only accessible under localhost by default.
You must then enter http://localhost:8080/ manually.

  • A browser bookmark isn't an option because you could set the quarkus.http.port to any option you wish (also 0 for a random port).
  • Changing /etc/hosts to work with Quarkus shouldn't be the point either, as it would make the poorer developer experience (on WSL, not your fault) the standard.

Unfortunately, the word 'listening' in the startup message is then no longer correct (under WSL dev/test) - as we are actually listening on 0.0.0.0. It's more like 'accessible in your browser on:'

Caution

Applications, including the amazon-lambda extension (AbstractLambdaPollLoop.java#L76) and the test-framework (LauncherUtil.java#L251) depend on this log message and I'm sure some developers will use it too for health checks and so on... At least i've seen this in the wild.

Copy link
Member

@radcortez radcortez left a comment

Choose a reason for hiding this comment

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

This PR conflicts with #40337. Any change should be done with that in mind.

@gsmet
Copy link
Member

gsmet commented May 10, 2024

@tamaro-skaljic OK, I better see your point. I need to think a bit about it as I think there are multiple things at play here and we need to take them all into account.

I'll have a closer look on Monday.

Copy link
Member

@gsmet gsmet left a comment

Choose a reason for hiding this comment

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

Hey there,

Sorry it took some time for me to think about it.

I agree with you that it would be better to make the link clickable. I also think that WSL networking is a bit of a corner case and it's not that big of a deal if we display localhost instead of 0.0.0.0 there. But we should only do it if the host is actually 0.0.0.0.
From what I could see in https://stackoverflow.com/questions/49835559/access-a-web-server-which-is-running-on-wsl-windows-subsystem-for-linux-from-t, even listening to 0.0.0.0 will only expose the service to the host when using WSL but maybe you could check?

Thanks for having a look, I think it's important to also have a seamless DevEx with WSL!

@gsmet
Copy link
Member

gsmet commented May 16, 2024

Ah, also, there is a conflict now due to the changes made by @radcortez here: https://github.com/quarkusio/quarkus/pull/40337/files .

So you will have to adjust your patch a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants