Skip to content

Only one port can be accessed by the host through localhost at the same time #4769

Closed

Description

@zed76r

Windows build number: 10.0.19536.1000

Steps to reproduce:

  1. Listen on port A vianc -l <PortA>.
  2. The browser accesses http://localhost:PortA, and the console can output the browser request body.
  3. Listen on port B via nc -l <PortB>.
  4. When the browser accesses http://localhost:PortB, the error ERR_CONNECTION_REFUSED directly appears.
  5. Shut down wsl2 through the wsl.exe --shutdown command, repeat the test in the order of 3, 4, 1, 2, and the result is that PortB can receive the packet, and PortA has an error ERR_CONNECTION_REFUSED.

Another reproduction method:

Using vscode's wsl-remote plug-in, it can be started correctly through the code . command for the first time. After closing vscode and using the command to open it again, the file under wsl cannot be displayed and an error message is displayed.

Activity

  1. BabyDino commented on Dec 17, 2019

    @BabyDino

    I think I'm running into this issue as well. I've just upgraded to 19536 and can't use vscode and my localhost:3000 app at the same time.

  2. ad-on-is commented on Dec 17, 2019

    @ad-on-is

    I have exactly the same issue:

    1. Opening a Remote WSL instance in VSCode (works)
    2. Run vue ui
    3. localhost:8000 gives error ERR_CONNECTION_REFUSED

    After wsl --shutdown

    1. Run vue ui
    2. localhost:8000 works
    3. Open a Remote WSL instance in VSCode gives error
      image
  3. wlbrough commented on Dec 17, 2019

    @wlbrough

    Similar issue to previous comments, but slightly different error path.

    Windows 10 Pro Insider Preview Build 19536.rs_prerelease.191211-1446 (WSL 2 Enabled)

    1. Open a Remote WSL instance.
    2. Start node server on WSL (running in a Docker container for an additional complication 🙂 )
    3. Cannot access the server at localhost:3000, which was working prior to Windows update.
  4. prsnnami commented on Dec 18, 2019

    @prsnnami

    Same issue, multiple connections to localhost doesn't work after the update 19536.1000

    Issue Identical to Adis Durakovic (@ad-on-is) 's comment.

    Don't know much about WSL's network arch to debug further.

  5. berwyn commented on Dec 18, 2019

    @berwyn

    I have noticed that this is infinitely more flakey than just one port being available.

    • I have Docker on my machine setup with WSL2 as its backend. I can run as many containers as I like on Docker and all the ports there get correctly exposed to the host.
    • With Ubuntu, however, only the first opened port ever gets exposed to the host, and even that never works if the process dies and then I try to re-bind that port (a good example being VS Code -- if I have to re-open the window, the port won't bind).
    • Lastly, with CentOS (which I installed to test a theory about the port issue), I can't bind any ports whatsoever, they all fail.

    Not sure what steps I can/should take to debug WSL2 networking, but I can confirm the update to 19536 is what broke me.

  6. benhillis commented on Dec 18, 2019

    @benhillis
    Member

    Thanks for reporting, there is an issue in Insider Fast, and a fix is coming in a future build (hopefully next week).

  7. alexisferat commented on Dec 19, 2019

    @alexisferat

    I have a LAMP setup on Ubuntu and I have the same issue. I cannot access my sites when using localhost.

    Until the fix is coming, I found a workaround. Do a ifconfig and take the inet value of the eth0 connection and use it instead of localhost (for example in your host file).

    The only problem is this address changes when the VM restart.

    Windows 10.0.19041

  8. GMory commented on Dec 19, 2019

    @GMory

    Is there a way to downgrade to previous build?

  9. berwyn commented on Dec 19, 2019

    @berwyn

    Settings -> Update & Security -> Recovery -> Go back to a previous version of Windows 10

    This should allow you to go back to the build you were running prior to this one. Make sure to pause updates from there, else your system will attempt to upgrade again to the problematic build.

    image

  10. OctavioBR commented on Dec 20, 2019

    @OctavioBR

    I witness that after 19536 update, it started to give me this same error.

  11. alechstong commented on Dec 24, 2019

    @alechstong

    I ran into this problem as well.
    I experimented a little and found out that the problem is better described as "one port per ip address".

    For example, I start server A on port 3000 and server B on 4000. If I access server A first on 127.0.01:3000 on the windows side, but I cannot access server B on 127.0.0.1:4000. However, I can access server B using wsl's ip address (let's say 172.23.134.64:4000). If I start another server C on port 5000, I cannot access it from either ip.

    So if you are like me, that are only running at most 2 servers in WSL, you are fine for now, and can wait for the update to drop.

  12. hristo-banchev commented on Jan 2, 2020

    @hristo-banchev

    Ben Hillis (@benhillis) would you share an update on the fix? Any vague ETA?

  13. puco commented on Jan 6, 2020

    @puco

    Any news on the fix?

  14. mituso89 commented on Jan 8, 2020

    @mituso89

    Any news on the fix?

  15. 58 remaining items

  16. e00dan commented on Jun 10, 2020

    @e00dan

    Why is this issue closed? :octocat:

  17. onomatopellan commented on Jun 10, 2020

    @onomatopellan

    kuzirashi Try disabling Fast Startup. If it works then you are hitting bug #5298

  18. sarim commented on Jun 17, 2020

    @sarim

    This issue comes and goes it seems. One day its working, next day its not. Some ports are working, some ports aren't. Not sure what is going on. Ex: last night everything was working, now i can't connect to my wsl's mysql from windows with localhost:3306. Where a http server running in 4444 is working fine.

    How does this localhost forward work actually? Can I run a powershell cmd to get a list of ports LXSS is current forwarding? Can I reset it? Edit it?

  19. onomatopellan commented on Jun 17, 2020

    @onomatopellan

    Sarim Khan (@sarim) Can you check if you have Fast Startup enabled?

  20. sarim commented on Jun 17, 2020

    @sarim

    I had fast startup enabled. But I had explicitly disabled hibernate from powercfg. AFAIK fast startup doesn't effectively enables if there is no hiberfil.sys. Which I don't have bcz I disabled hibernate. Nevertheless I explicitly disabled fast startup from registry.

  21. sarim commented on Jun 22, 2020

    @sarim

    It happened again. Restarting LxssManager from Task Manager -> Services didn't help. Had to restart windows. Now its working.

  22. lemchen commented on Jun 27, 2020

    @lemchen

    It happened again. some specific ports not working for localhost:ports, but some other ports works. for example, i run node use localhost:3000 doesn't work, by changing the port number it does.

  23. onomatopellan commented on Jun 27, 2020

    @onomatopellan

    stoner chen (@lemchen) That sounds like docker/for-win#7196
    What's the output of netsh int ipv4 show dynamicport tcp ?

  24. lemchen commented on Jun 27, 2020

    @lemchen

    stoner chen (@lemchen) That sounds like docker/for-win#7196
    What's the output of netsh int ipv4 show dynamicport tcp ?

    yes , the port is in the range of excludedportrange by using netsh interface ipv4 show excludedportrange protococol=tcp.
    i have solved this problem by disable Hyper-V function and re-enable it.

  25. a-abella commented on Aug 3, 2020

    @a-abella

    I've began experiencing (I think) some manifestation of this issue. I am not limited to one bound port at a time, but which ports are accessible from the Windows host seems arbitrary. I had ports 3000 and 222 working yesterday. After a shutdown, they are not working today. Additional testing of random ports has yielded the following results:

    (testing methodology: sudo netcat -kl 0.0.0.0 $port from wsl2, and try to access from browser on Windows host)

    Working:
    1024
    1025
    1026
    1027
    1194
    2111
    4099
    4170
    4455
    4567
    6974
    
    Not working:
    1111
    2024
    2025
    2026
    2027
    2255
    3000
    3005
    3456
    4000
    4001
    4002
    4003
    

    The ports that work always work, even after wsl --shutdown. The ports that fail always fail. I'm curious what the condition is that causes this.

    The WSL-side iptables are blank:

    iptables-save output
    # Generated by iptables-save v1.6.1 on Sun Aug  2 22:18:51 2020
    *security
    :INPUT ACCEPT [29:3752]
    :FORWARD ACCEPT [0:0]
    :OUTPUT ACCEPT [27:3286]
    COMMIT
    # Completed on Sun Aug  2 22:18:51 2020
    # Generated by iptables-save v1.6.1 on Sun Aug  2 22:18:51 2020
    *raw
    :PREROUTING ACCEPT [49:8733]
    :OUTPUT ACCEPT [27:3286]
    COMMIT
    # Completed on Sun Aug  2 22:18:51 2020
    # Generated by iptables-save v1.6.1 on Sun Aug  2 22:18:51 2020
    *nat
    :PREROUTING ACCEPT [0:0]
    :INPUT ACCEPT [0:0]
    :OUTPUT ACCEPT [0:0]
    :POSTROUTING ACCEPT [0:0]
    COMMIT
    # Completed on Sun Aug  2 22:18:51 2020
    # Generated by iptables-save v1.6.1 on Sun Aug  2 22:18:51 2020
    *mangle
    :PREROUTING ACCEPT [49:8733]
    :INPUT ACCEPT [29:3752]
    :FORWARD ACCEPT [0:0]
    :OUTPUT ACCEPT [27:3286]
    :POSTROUTING ACCEPT [27:3286]
    COMMIT
    # Completed on Sun Aug  2 22:18:51 2020
    # Generated by iptables-save v1.6.1 on Sun Aug  2 22:18:51 2020
    *filter
    :INPUT ACCEPT [29:3752]
    :FORWARD ACCEPT [0:0]
    :OUTPUT ACCEPT [27:3286]
    COMMIT
    # Completed on Sun Aug  2 22:18:51 2020
    # Generated by iptables-save v1.6.1 on Sun Aug  2 22:18:51 2020
    *security
    :INPUT ACCEPT [29:3752]
    :FORWARD ACCEPT [0:0]
    :OUTPUT ACCEPT [27:3286]
    COMMIT
    # Completed on Sun Aug  2 22:18:51 2020
    # Generated by iptables-save v1.6.1 on Sun Aug  2 22:18:51 2020
    *raw
    :PREROUTING ACCEPT [49:8733]
    :OUTPUT ACCEPT [27:3286]
    COMMIT
    # Completed on Sun Aug  2 22:18:51 2020
    # Generated by iptables-save v1.6.1 on Sun Aug  2 22:18:51 2020
    *nat
    :PREROUTING ACCEPT [0:0]
    :INPUT ACCEPT [0:0]
    :OUTPUT ACCEPT [0:0]
    :POSTROUTING ACCEPT [0:0]
    COMMIT
    # Completed on Sun Aug  2 22:18:51 2020
    # Generated by iptables-save v1.6.1 on Sun Aug  2 22:18:51 2020
    *mangle
    :PREROUTING ACCEPT [49:8733]
    :INPUT ACCEPT [29:3752]
    :FORWARD ACCEPT [0:0]
    :OUTPUT ACCEPT [27:3286]
    :POSTROUTING ACCEPT [27:3286]
    COMMIT
    # Completed on Sun Aug  2 22:18:51 2020
    # Generated by iptables-save v1.6.1 on Sun Aug  2 22:18:51 2020
    *filter
    :INPUT ACCEPT [29:3752]
    :FORWARD ACCEPT [0:0]
    :OUTPUT ACCEPT [27:3286]
    COMMIT
    # Completed on Sun Aug  2 22:18:51 2020
    
  26. onomatopellan commented on Aug 3, 2020

    @onomatopellan

    Antonio Abella (@a-abella) Open an elevated Powershell and post the output of these:
    netsh int ipv4 show excludedportrange protocol=tcp
    netsh int ipv4 show dynamicport tcp

  27. a-abella commented on Aug 3, 2020

    @a-abella

    Jonathan (@onomatopellan)

    Aha, I knew about show dynamicport but not the excludedportrange.

    Protocol tcp Port Exclusion Ranges
    
    Start Port    End Port
    ----------    --------
          1028        1127
          1239        1338
          1675        1774
          1775        1874
          1875        1974
          1975        2074
          2075        2174
          2180        2279
          2280        2379
          2380        2479
          2480        2579
          2580        2679
          4514        4613
          4614        4713
          4714        4813
          4814        4913
          4914        5013
          5041        5140
          5141        5240
          5241        5340
          5355        5454
          5455        5554
          5555        5654
          5655        5754
         50000       50059     *
    
    * - Administered port exclusions.
    
    PS C:\WINDOWS\system32>
    PS C:\WINDOWS\system32> netsh int ipv4 show dynamicport tcp
    
    Protocol tcp Dynamic Port Range
    ---------------------------------
    Start Port      : 1024
    Number of Ports : 64511
    

    This is after a reboot since my previous comment, so it looks like the exclusions affecting my random port findings are now different.

    Your comment led me to #5306 , which suggested moving the dynamic port range with netsh int ipv4 set dynamic tcp start=49152 num=16384 Presumably an Insider update or something moved the Start Port to 1024.

    After moving the Start Port and rebooting things look sane again, and I can bind ports reliably from WSL2 again.

    Thanks a lot!

  28. ntrp commented on Aug 18, 2020

    @ntrp

    Thanks for this, I wasted 4 hours finding out why it does not work... Did not think about changing port after seeing that a demo python server on 8000 was working fine...

  29. danielcinome commented on Feb 13, 2021

    @danielcinome

    19541 Parece que el vscode fijo no puede "recuperar el entorno remoto",

    Sin embargo, NO parece haber solucionado el problema de no poder acceder a más de un puerto a la vez.

    Tengo un proyecto de React que se ejecuta localhost:3000y un proyecto de Gatsby que se ejecuta localhost:8000, antes de este problema, podía ejecutar ambos simultáneamente y acceder a ellos desde Windows en Chrome.

    Siga estos pasos para recrear el comportamiento:

    • Abrir WSL2
    • Vaya al directorio raíz del proyecto React y ejecute npm startpara iniciar el servidor en ejecuciónlocalhost:3000
    • En una nueva pestaña, vaya al directorio raíz del proyecto Gatsby y ejecute npm start, esto inicia el servidor enlocalhost:8000
    • Abra Google Chrome y vaya a localhost:3000, debería ver el proyecto de reacción.
    • Ahora intente ir a localhost:8000, no podrá ver el proyecto Gatsby, y debería ver un error como el siguiente:

    imagen

    Lo divertido es que puede detener ambos servidores, SOLO iniciar el proyecto gatsby localhost:8000y obtendrá el mismo error, pero si inicia otro proyecto de reacción, estará bien localhost:3000.

    Parece que el primer puerto que usa mientras WSL2 está activo y se convierte en el único que puede ver desde Windows, ejecutarse wsl --shutdownen una ventana del símbolo del sistema e iniciar WSL2 nuevamente parece restablecer la pizarra, así que diga ahora que inicia el proyecto Gatsby localhost:8000primero luego deténgalo de inmediato, no podrá ver ninguna aplicación ejecutándose localhost:3000si las inicia después de iniciar la localhost:8000aplicación, solo tendrá el puerto 8000 visible en Windows.

    this has worked for me, thank you.

  30. gxtaillon commented on Apr 25, 2021

    @gxtaillon

    Same problem as described above. Setup working fine with Docker for Windows & Kube. After restarting the computer, nothing works from the windows side. Running wsl --shutdown, restarting docker from the UI and rerunning kubectl proxy, now everything works fine.

    Edit 1: 2/2 restarts where Docker was set to run on startup this issue has occurred. I disabled this setting and i'll see what happens if Docker is started manually after a restart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions