"Connection refused: connect" in Http Client when querying localhost.
I try to configure development on Windows with WSL 2.
I've managed to import, compile and run a simple Spring Boot application with a /users endpoint.
I got a response from localhost:8080/users using telnet via Windows command propt:
telnet localhost 8080
GET /users
result:
["Foo","Bar"]
Connection to host lost.
I can get a response with a WCL console too, with
$ curl -X GET --location "http://localhost:8080/users"
["Foo","Bar"]
command.
...but not with Idea's HTTP Client
###
GET http://localhost:8080/users
result:
http://localhost:8080/users
org.apache.http.conn.HttpHostConnectException: Connect to localhost:8080 [localhost/127.0.0.1] failed: Connection refused: connect
- I did run the "Fix Firewall" action in IDE
- There is no error message in Spring Boot log
- I run Spring Boot application on WSL target
- Got the same result when running on "Local Machine" though
- Got the same result after completely disabling Windows Defender Firewall
- I don't have any other firewall software installed.
- I am a simple man and I don't have any unusual network configuration.
IntelliJ IDEA 2022.2 (Ultimate Edition)
Build #IU-222.3345.118, built on July 26, 2022
Licensed to Jacek Gajek
Subscription is active until September 11, 2022.
Runtime version: 17.0.3+7-b469.32 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 8000M
Cores: 12
Registry:
undo.documentUndoLimit=9999
ide.images.show.chessboard=true
js.debugger.webconsole=false
Non-Bundled Plugins:
send2terminal (1.5.3)
org.turbanov.run.configuration.as.action (1.4.5)
org.sylfra.idea.plugins.linessorter (1.0.1)
org.intellij.RegexpTester (1.0.8)
net.seesharpsoft.intellij.plugins.csv (2.19.0)
main.kotlin.com.jimschubert.intellij.swaggercodegen (4.3.1-p0)
de.ax.powermode (102.201)
com.sburlyaev.terminal.plugin (0.4.5)
com.jinsihou.react.snippets (1.1.0)
com.jetbrains.plugins.ini4idea (222.3345.108)
com.intellij.plugins.watcher (222.3345.111)
com.intellij.ideolog (203.0.30.0)
marcglasberg.HibernateInspectionsPlugin (1.6)
de.u-mass.idea.copyConstructor (1.2)
com.linsage (1.0.7)
com.intellij.apacheConfig (222.3345.108)
com.github.syuchan1005.ImageComment (1.0.3)
com.github.leomillon.uuidgenerator (4.5.1)
com.euphoricity.gitignore (0.3)
com.bluewaitor.tsReact (1.4.0)
br.com.matheusfm.jsonutils (1.2)
YAML/Ansible support (0.11.2)
Statistic (4.1.10)
IvyIDEA (1.0.16)
IdeaVIM (1.10.3)
mobi.hsz.idea.gitignore (4.4.2)
nl.rubensten.texifyidea (0.7.19)
PlantUML integration (5.16.1)
org.zalando.intellij.swagger (1.1.2)
org.jetbrains.plugins.ruby (222.3345.118)
Dilbert (1.9.0.168)
Base64 for IDEA and Storm (1.1b)
com.intellij.plugins.html.instantEditing (222.3345.108)
com.jetbrains.php (222.3345.118)
com.ifengxue.plugin.jpa-support (2.1.0-RC2)
com.deadlock.scsyntax (222.3345.108)
Pythonid (222.3345.131)
org.exbin.deltahex.intellij (0.2.6)
net.ashald.envfile (3.2.2)
com.intellij.react.css.modules (1.0.1)
org.intellij.scala (2022.2.10)
com.moxun.plugin.s2v (1.9.2)
com.mistamek.drawablepreview.drawable-preview (1.1.6)
com.bruce.intellijplugin.generatesetter (2.8.1)
Kotlin: 222-1.7.10-release-334-IJ3345.118
请先登录再写评论。
Hello,
Does it help if you use IP address instead? (may be related to https://github.com/microsoft/WSL/discussions/6253)
You may also try adding -Djava.net.preferIPv6Addresses=true to the run configuration's VM options:
No, I've already tried both of these options. Sorry for not including that in the original post.
I also have tried -Djava.net.preferIPv4Addresses=false which I suppose does the same thing.
I created a new usability problem report for this on our system: https://youtrack.jetbrains.com/issue/IDEA-299087
We will come up with a way to handle this.
As a workaround, try running the server with server.address=0.0.0.0 (see similar issue with Quarkos: https://github.com/quarkusio/quarkus/issues/22887)
Thanks for support. Unfortunately setting "server.address=0.0.0.0" in application.properties didn't change anything for me.
When I run the app by IDE on Local Machine, the only part related to WSL is the java runtime, which happens to be located on the Linux subsystem, right? Shouldn't be an issue... any other ideas?
Thanks for the info.
I'll ask the developers to look into it. If there's another workaround, will let you know.
For the record, the Http Client works if I launch Idea from WSL console, via VcXsrv. But it's not a workaround, rather a curiosity. WSL 2 (at least on Windows 10) is not suited to run GUI apps for many reasons, even if it's technically possible.
I can access localhost endpoints via PostMan.
This code, when run with Idea's "play" button, also works when targeted Local Machine or WSL.
I'm also having this issue on IntelliJ IDEA 2022.2.2 (Ultimate Edition)
Two IDEA projects are open: IDEA #1 is a Spring project on the WSL 2 filesystem. IDEA #2 is a separate Java project on the Windows filesystem. I'm running project #1 to serve an API, and trying to make a request to the API from an apache HttpClient in a unit test on #2. I can hit the endpoint successfully from the Jetbrains HTTP Client on both #1 and #2 (or from the browser, or postman, etc), but it's showing "Connection Refused: connect" when trying to run the code itself in IDEA #2.
Also note, when I deploy the API to https://some.deployed.location.com the code works just fine. So it seems to specifically be some problem with IDEA #2 on Windows running the code, which is trying to connect to a local Spring instance running on WSL 2.