WSL2 - "Connection Refused" when sync maven
已回答
IntelliJ V. 2021.2.3
Host: Windows 10 build 19044
WSL2: Distribution Ubuntu installed in the host machine
I'm having the next error when I try to sync maven:
java.util.concurrent.ExecutionException: java.rmi.ConnectException: Connection refused to host: 172.19.251.203; nested exception is:
java.net.ConnectException: Connection refused: connect
The IP is the eth0 of the WSL2 machine (is a random IP that changes every time I restart the WSL2 system). I can do ping from the host and from the machine to the host. In the WSL2 firewall does not exist any rule and the default policy is ACCEPT. I have tried the option "Fix WSL Firewall Settings" of IntelliJ but without any result.
The log of IntelliJ when I sync maven is the next:
INFO - #org.jetbrains.idea.maven - Creating new maven connector for Project(name=core, containerState=COMPONENT_CREATED, componentStore=\\wsl$\Ubuntu\opt\src\eplus\epsilon\core) in //wsl$/Ubuntu/opt/src/eplus/epsilon/core
INFO - #org.jetbrains.idea.maven - Connecting maven connector in //wsl$/Ubuntu/opt/src/eplus/epsilon/core
INFO - #org.jetbrains.idea.maven - Use WSL maven distribution at //wsl$/Ubuntu/opt/maven/apache-maven-3.2.1(\\wsl$\Ubuntu\opt\maven\apache-maven-3.2.1) v 3.2.1
INFO - #com.intellij.execution.wsl - Failed to execute C:\Windows\system32\wsl.exe [--distribution, Ubuntu, --exec, /bin/bash, -i, -l, -c, echo 'intellij: executing command...' && printenv MAVEN_OPTS] for Ubuntu: exitCode=1, timeout=false, stdout=, stderr=
INFO - #org.jetbrains.idea.maven - Staring maven server on WSL as /usr/java/jdk1.8.0_321/bin/java -Djava.awt.headless=true -Dmaven.defaultProjectBuilder.disableGlobalModelCache=true -Didea.version=2021.2.3 -Didea.maven.embedder.version=3.2.1 -Xmx768m -Dmaven.ext.class.path=C:\Program Files\JetBrains\IntelliJ IDEA 2021.2.3\plugins\maven\lib\maven-event-listener.jar -classpath /mnt/c/Program Files/JetBrains/IntelliJ IDEA 2021.2.3/lib/util.jar:/mnt/c/Program Files/JetBrains/IntelliJ IDEA 2021.2.3/lib/annotations.jar:/mnt/c/Program Files/JetBrains/IntelliJ IDEA 2021.2.3/plugins/maven/lib/lucene-core-2.4.1.jar:/mnt/c/Program Files/JetBrains/IntelliJ IDEA 2021.2.3/plugins/maven-model/lib/maven-model.jar:/mnt/c/Program Files/JetBrains/IntelliJ IDEA 2021.2.3/plugins/maven/lib/maven-server-api.jar:/mnt/c/Program Files/JetBrains/IntelliJ IDEA 2021.2.3/plugins/maven/lib/maven3-server-common.jar:/mnt/c/Program Files/JetBrains/IntelliJ IDEA 2021.2.3/plugins/maven/lib/maven3-server-lib/archetype-catalog-2.2.jar:/mnt/c/Program Files/JetBrains/IntelliJ IDEA 2021.2.3/plugins/maven/lib/maven3-server-lib/archetype-common-2.2.jar:/mnt/c/Program Files/JetBrains/IntelliJ IDEA 2021.2.3/plugins/maven/lib/maven3-server-lib/maven-dependency-tree-1.2.jar:/mnt/c/Program Files/JetBrains/IntelliJ IDEA 2021.2.3/plugins/maven/lib/maven3-server-lib/nexus-indexer-3.0.4.jar:/mnt/c/Program Files/JetBrains/IntelliJ IDEA 2021.2.3/plugins/maven/lib/maven3-server-lib/nexus-indexer-artifact-1.0.1.jar:/mnt/c/Program Files/JetBrains/IntelliJ IDEA 2021.2.3/plugins/maven/lib/maven3-server.jar:/opt/maven/apache-maven-3.2.1/lib/maven-plugin-api-3.2.1.jar:/opt/maven/apache-maven-3.2.1/lib/jsoup-1.7.2.jar:/opt/maven/apache-maven-3.2.1/lib/jsr250-api-1.0.jar:/opt/maven/apache-maven-3.2.1/lib/aopalliance-1.0.jar:/opt/maven/apache-maven-3.2.1/lib/wagon-provider-api-2.6.jar:/opt/maven/apache-maven-3.2.1/lib/aether-api-0.9.0.M2.jar:/opt/maven/apache-maven-3.2.1/lib/cdi-api-1.0.jar:/opt/maven/apache-maven-3.2.1/lib/org.eclipse.sisu.plexus-0.0.0.M5.jar:/opt/maven/apache-maven-3.2.1/lib/guava-14.0.1.jar:/opt/maven/apache-maven-3.2.1/lib/aether-connector-wagon-0.9.0.M2.jar:/opt/maven/apache-maven-3.2.1/lib/maven-model-builder-3.2.1.jar:/opt/maven/apache-maven-3.2.1/lib/maven-model-3.2.1.jar:/opt/maven/apache-maven-3.2.1/lib/sisu-guice-3.1.3-no_aop.jar:/opt/maven/apache-maven-3.2.1/lib/slf4j-api-1.7.5.jar:/opt/maven/apache-maven-3.2.1/lib/plexus-utils-3.0.17.jar:/opt/maven/apache-maven-3.2.1/lib/commons-cli-1.2.jar:/opt/maven/apache-maven-3.2.1/lib/maven-artifact-3.2.1.jar:/opt/maven/apache-maven-3.2.1/lib/maven-aether-provider-3.2.1.jar:/opt/maven/apache-maven-3.2.1/lib/commons-lang-2.6.jar:/opt/maven/apache-maven-3.2.1/lib/slf4j-simple-1.7.5.jar:/opt/maven/apache-maven-3.2.1/lib/plexus-interpolation-1.19.jar:/opt/maven/apache-maven-3.2.1/lib/maven-embedder-3.2.1.jar:/opt/maven/apache-maven-3.2.1/lib/wagon-http-shared-2.6.jar:/opt/maven/apache-maven-3.2.1/lib/maven-compat-3.2.1.jar:/opt/maven/apache-maven-3.2.1/lib/wagon-file-2.6.jar:/opt/maven/apache-maven-3.2.1/lib/aether-util-0.9.0.M2.jar:/opt/maven/apache-maven-3.2.1/lib/plexus-component-annotations-1.5.5.jar:/opt/maven/apache-maven-3.2.1/lib/aether-spi-0.9.0.M2.jar:/opt/maven/apache-maven-3.2.1/lib/maven-core-3.2.1.jar:/opt/maven/apache-maven-3.2.1/lib/plexus-sec-dispatcher-1.3.jar:/opt/maven/apache-maven-3.2.1/lib/wagon-http-2.6-shaded.jar:/opt/maven/apache-maven-3.2.1/lib/plexus-cipher-1.7.jar:/opt/maven/apache-maven-3.2.1/lib/maven-repository-metadata-3.2.1.jar:/opt/maven/apache-maven-3.2.1/lib/commons-io-2.2.jar:/opt/maven/apache-maven-3.2.1/lib/aether-impl-0.9.0.M2.jar:/opt/maven/apache-maven-3.2.1/lib/org.eclipse.sisu.inject-0.0.0.M5.jar:/opt/maven/apache-maven-3.2.1/lib/maven-settings-3.2.1.jar:/opt/maven/apache-maven-3.2.1/lib/javax.inject-1.jar:/opt/maven/apache-maven-3.2.1/lib/maven-settings-builder-3.2.1.jar:/opt/maven/apache-maven-3.2.1/boot/plexus-classworlds-2.5.1.jar -Djava.rmi.server.hostname=172.19.251.203 -Didea.maven.wsl=true -Dfile.encoding=windows-1252 org.jetbrains.idea.maven.server.RemoteMavenServer
INFO - #org.jetbrains.idea.maven - Sent token to maven server
INFO - ution.rmi.RemoteProcessSupport - Terminating: 172.19.251.203:23839/Maven3ServerImpl399d03f
INFO - process.KillableProcessHandler - Skipping WinP graceful termination for C:\Windows\System32\wsl.exe due to incorrect work with WSL processes
If you need more detailed information please tell me.
请先登录再写评论。
The
error means that the remote socket is blocked for connections. Please check these articles to configure the WSL and Windows machines network and firewall configuration:
https://www.jetbrains.com/help/idea/how-to-use-wsl-development-environment-in-product.html#debugging_system_settings
https://stackoverflow.com/a/68772672/2000323
Thank you for the comment.
I've followed the steps and now I have allow policy for all profiles and type of packets (two rules with profile "domain,private" and each one with packets TCP or UDP respectively, and other two with profile "public") for Intellij rules. I've created the rule to allow connections using WSL too. I've tried to restart IntelliJ and WSL but the error still appears.
Something in your environment still blocks the IDE connections to the WSL interface. If you have antivirus, try disabling or un-installing it completely. Double check your network DNS configuration on Windows and WSL hosts (see https://intellij-support.jetbrains.com/hc/en-us/articles/360014262940).
Sorry for my late reply.
I disabled the antivirus and I checked that my hosts files where correct in Windows and WSL machines, but the error still appears. Following the first advice I tried to configure firewall for Java rules like I did for IntelliJ and then I disabled firewall completely but the same problem occurs.
Could it be some permissions problem?
What is the content of /etc/hosts on WSL host? What ip interfaces do you have on WSL machine? Do you use VPNs?
See also this comment about firewall configuration.
This is my WSL host /etc/hosts content :
And this my WSL machine /etc/hosts:
My WSL machine interfaces are these:
Yes I use VPN but WSL machine is installed locally, anyway I have also tried it with the VPN turned off.
>And this my WSL machine /etc/hosts:
Try leaving only one single localhost mapping here as mentioned in https://intellij-support.jetbrains.com/hc/en-us/articles/360014262940
I've let only the ipv4 localhost address in WSL machine /etc/hosts without any result, the connection is refused to host of WSL machine eth0.
>the connection is refused to host of WSL machine eth0.
What is the full error?
The full error is:
org.jetbrains.idea.maven.server.CannotStartServerException: java.util.concurrent.ExecutionException: java.rmi.ConnectException: Connection refused to host: 172.26.39.249; nested exception is:
java.net.ConnectException: Connection refused: connect
at org.jetbrains.idea.maven.server.MavenServerConnectorImpl.getServer(MavenServerConnectorImpl.java:107)
at org.jetbrains.idea.maven.server.MavenServerConnector.lambda$applyProfiles$3(MavenServerConnector.java:85)
at org.jetbrains.idea.maven.server.MavenServerConnectorImpl.perform(MavenServerConnectorImpl.java:176)
at org.jetbrains.idea.maven.server.MavenServerConnector.applyProfiles(MavenServerConnector.java:84)
at org.jetbrains.idea.maven.project.MavenProjectReader.applyProfiles(MavenProjectReader.java:421)
at org.jetbrains.idea.maven.project.MavenProjectReader.doReadProjectModel(MavenProjectReader.java:96)
at org.jetbrains.idea.maven.project.MavenProjectReader.readProject(MavenProjectReader.java:54)
at org.jetbrains.idea.maven.project.MavenProject.read(MavenProject.java:641)
at org.jetbrains.idea.maven.project.MavenProjectsTree.doUpdate(MavenProjectsTree.java:549)
at org.jetbrains.idea.maven.project.MavenProjectsTree.update(MavenProjectsTree.java:459)
at org.jetbrains.idea.maven.project.MavenProjectsTree.updateAll(MavenProjectsTree.java:427)
at org.jetbrains.idea.maven.project.MavenProjectsProcessorReadingTask.perform(MavenProjectsProcessorReadingTask.java:61)
at org.jetbrains.idea.maven.project.MavenProjectsProcessor.doProcessPendingTasks(MavenProjectsProcessor.java:146)
at org.jetbrains.idea.maven.project.MavenProjectsProcessor$1.run(MavenProjectsProcessor.java:115)
at org.jetbrains.idea.maven.utils.MavenUtil.lambda$runInBackground$6(MavenUtil.java:534)
at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:265)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.util.concurrent.ExecutionException: java.rmi.ConnectException: Connection refused to host: 172.26.39.249; nested exception is:
java.net.ConnectException: Connection refused: connect
at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:395)
at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1999)
at org.jetbrains.concurrency.AsyncPromise.get(AsyncPromise.kt:42)
at org.jetbrains.idea.maven.server.MavenServerConnectorImpl.waitForServer(MavenServerConnectorImpl.java:124)
at org.jetbrains.idea.maven.server.MavenServerConnectorImpl.getServer(MavenServerConnectorImpl.java:88)
... 24 more
Caused by: java.rmi.ConnectException: Connection refused to host: 172.26.39.249; nested exception is:
java.net.ConnectException: Connection refused: connect
at java.rmi/sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:623)
at java.rmi/sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:209)
at java.rmi/sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:196)
at java.rmi/sun.rmi.server.UnicastRef.newCall(UnicastRef.java:343)
at java.rmi/sun.rmi.registry.RegistryImpl_Stub.lookup(RegistryImpl_Stub.java:116)
at com.intellij.execution.rmi.RemoteProcessSupport.lambda$acquire$2(RemoteProcessSupport.java:312)
at com.intellij.openapi.util.ClassLoaderUtil.computeWithClassLoader(ClassLoaderUtil.java:31)
at com.intellij.execution.rmi.RemoteUtil.executeWithClassLoader(RemoteUtil.java:202)
at com.intellij.execution.rmi.RemoteProcessSupport.acquire(RemoteProcessSupport.java:310)
at com.intellij.execution.rmi.RemoteProcessSupport.acquire(RemoteProcessSupport.java:185)
at org.jetbrains.idea.maven.server.MavenServerConnectorImpl$StartServerTask.run(MavenServerConnectorImpl.java:261)
... 10 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.base/java.net.PlainSocketImpl.connect0(Native Method)
at java.base/java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:101)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.base/java.net.Socket.connect(Socket.java:609)
at java.base/java.net.Socket.connect(Socket.java:558)
at java.base/java.net.Socket.<init>(Socket.java:454)
at java.base/java.net.Socket.<init>(Socket.java:231)
at com.intellij.execution.rmi.RemoteServer$1.createSocket(RemoteServer.java:150)
at java.rmi/sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:617)
... 20 more
AFAIU the connection must be made to 127.0.0.1 host. Not sure why in your case it is made to 172.26.39.249 interface. May be this is expected. Either way, the access to this interface in the machine is restricted. Please look into the machine configuration to allow the connections.
Sure enough, in others errors I always seen the connection refused is to 127.0.0.1 host. I don't know how IntelliJ gets the ip of WSL machine eth0 interface and i don't know if this could be causing the error.
I checked that WSL machine iptables is empty and default policy for all tables is "Accept". I've noticed that from windows I could ping but no connect via ssh, then I resolved this and now I can connect but the error is the same. I have also looked that "UFW" did not have any blocking rule but I realised that was disabled, when I enabled and I added this rule:
the error has changed to "connection timed out" (don't know if this is important).
I don't know any other cause that could be blocking interface eth0 of my WSL machine.