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

[Bug] Getting connect ECONNREFUSED when app is running on localhost #7017

Open
1 of 2 tasks
15m43lk4155y opened this issue Oct 1, 2024 · 12 comments
Open
1 of 2 tasks
Labels
bug Something isn't working triage This issue needs to be triaged by a maintainer

Comments

@15m43lk4155y
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

OS/Web Information

  • Web Browser: Chrome
  • Local OS: Ubuntu
  • Docker image: codercom/code-server
  • code-server --version: 4.91.1

Steps to Reproduce

  1. docker container running locally with the image built using the following Dockerfile:
FROM codercom/code-server:4.91.1

CMD ["dumb-init", "code-server", "--proxy-domain", "{{port}}.customdomain.tld", "--port", "8443", "--auth", "none"]
  1. local DNS pointing customdomain.tld to 127.0.0.1
  2. NGINX reverse proxy that points to the code-server instance with two .conf files:
server {
    listen 80;
    server_name customdomain.tld;
    location / {
        proxy_pass http://container_ip:8443;
        proxy_set_header Host $host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection upgrade;
        proxy_set_header Accept-Encoding gzip;
    }
}

and

server {
    listen 80;
    server_name ~^(\d+)\.customdomain\.tld$;
    location / {
        proxy_pass http://container_ip:8443;
        proxy_set_header Host $host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection upgrade;
        proxy_set_header Accept-Encoding gzip;
    }
}
  1. run http server in the code server terminal using python -m http.server -b localhost then open 8000.customdomain.tld in the browser

Expected

It should show the http server correctly

Actual

the following error displays:
Screenshot from 2024-10-01 04-28-46
Note that when running python -m http.server -b 127.0.0.1 the server is shown correctly as per the following image:
Screenshot from 2024-10-01 04-31-04

Logs

No response

Screenshot/Video

No response

Does this bug reproduce in native VS Code?

I did not test native VS Code

Does this bug reproduce in GitHub Codespaces?

I did not test GitHub Codespaces

Are you accessing code-server over a secure context?

  • I am using a secure context.

Notes

This was tested using an angular app as well (since the host is localhost by default in it) and the same happens when I set the host in ng serve to 127.0.0.1 the app is shown correctly when I leave it by default (aka localhost) it doesn't

@15m43lk4155y 15m43lk4155y added bug Something isn't working triage This issue needs to be triaged by a maintainer labels Oct 1, 2024
@code-asher
Copy link
Member

code-asher commented Oct 1, 2024

Huh, I would expect both localhost and 127.0.0.1 to be inaccessible if they are inside the Docker container but 127.0.0.1 works for the Angular app? Does code-server work if you bind code-server to 0.0.0.0?

CMD ["dumb-init", "code-server", "--proxy-domain", "{{port}}.customdomain.tld", "--auth", "none", "--bind-addr", "0.0.0.0:8443"]

@code-asher
Copy link
Member

code-asher commented Oct 1, 2024

Oh sorry I misunderstood, you are getting that error through code-server's built-in proxy. 8000.customdomain.tld will try to proxy whatever is on port 8000, so this error means nothing is running at the address 0.0.0.0:8000.

@code-asher
Copy link
Member

If 127.0.0.1 works but not localhost, is it possible the Angular app is binding to ipv6?

@15m43lk4155y
Copy link
Author

Huh, I would expect both localhost and 127.0.0.1 to be inaccessible if they are inside the Docker container but 127.0.0.1 works for the Angular app? Does code-server work if you bind code-server to 0.0.0.0?

CMD ["dumb-init", "code-server", "--proxy-domain", "{{port}}.customdomain.tld", "--auth", "none", "--bind-addr", "0.0.0.0:8443"]

Sorry for the miss I do actually bind it to 0.0.0.0 (what I gave is an earlier version of the Dockerfile, what I am using now is the following):
CMD ["dumb-init", "code-server", "--auth", "none", "--bind-addr", "0.0.0.0:8443", "--proxy-domain", "{{port}}.customdomain.tld"]

If 127.0.0.1 works but not localhost, is it possible the Angular app is binding to ipv6?

Well upon further tests I found out that this might be the case given the following tests:

The following displays the server correctly on 8000.customdomain.tld
Screenshot from 2024-10-01 20-45-35

The following displays the server correctly on 8000.customdomain.tld
Screenshot from 2024-10-01 20-45-44

The following gives connect ECONNREFUSED 0.0.0.0:8000 on 8000.customdomain.tld
Screenshot from 2024-10-01 20-46-01

So the issue as I understand is that the built-in proxy forwards the request to 0.0.0.0 even when the running server is binding to ipv6?

@15m43lk4155y
Copy link
Author

@code-asher can you please give me an update on this issue on the light of my recent comment

@nomaddevops
Copy link

Hello there,
I'm experiencing the exact same issue running backstage (https://github.com/backstage/backstage)
Image don't really know why but the proxy return econnrefused.

If i'm running curl from my code-server instance this is working
For the record i'm running code-server under microk8s

@code-asher
Copy link
Member

Hey, sorry for the delayed response.

So the issue as I understand is that the built-in proxy forwards the request to 0.0.0.0 even when the running server is binding to ipv6?

I think this is the case, yes. Possibly we should forward to localhost instead of 0.0.0.0.

@code-asher
Copy link
Member

don't really know why but the proxy return econnrefused.

Maybe this is the same thing, can you make Backstage listen on 127.0.0.1 explicitly?

@nomaddevops
Copy link

don't really know why but the proxy return econnrefused.

Maybe this is the same thing, can you make Backstage listen on 127.0.0.1 explicitly?

Hey @code-asher sorry for my late response

I've just try it out, it looks like i'm being redirect but webpack return an invalid host header, this more related to how backstage is launch from my point of view

@code-asher
Copy link
Member

Oh interesting. It might be because we proxy to 0.0.0.0 which does not match 127.0.0.1. Maybe listening on 0.0.0.0 will work?

@nomaddevops
Copy link

Oh interesting. It might be because we proxy to 0.0.0.0 which does not match 127.0.0.1. Maybe listening on 0.0.0.0 will work?

I've made some other tests i've configured my backstage like that
baseUrl: http://<my-code-server>/absproxy/3000 listen: port: 3000 host: 0.0.0.0
andrun the following command PUBLIC_URL=/absproxy/3000 WDS_SOCKET_PATH=$PUBLIC_URL/sockjs-node BROWSER=none yarn dev
This is almost working, just have an issue on wss redirect

@code-asher
Copy link
Member

Nice! Not sure on the wss redirect, seems weird if it is using http.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage This issue needs to be triaged by a maintainer
Projects
None yet
Development

No branches or pull requests

3 participants