code-server icon indicating copy to clipboard operation
code-server copied to clipboard

Web socket fails to connect through Apache

Open lplassman opened this issue 4 years ago • 52 comments

OS/Web Information

  • Web Browser: Chrome
  • Local OS: MacOS 12.2
  • Remote OS: Ubuntu 20.04 LTS
  • Remote Architecture: amd64
  • code-server --version: 4.0.1

Logs

code-server --log debug [2022-01-11T03:38:43.612Z] info code-server 4.0.1 735c6da829535969ff7193c79379299e4a1cb9bc [2022-01-11T03:38:43.613Z] info Using user-data-dir ~/.local/share/code-server [2022-01-11T03:38:43.628Z] info Using config file ~/.config/code-server/config.yaml [2022-01-11T03:38:43.628Z] info HTTP server listening on http://0.0.0.0:8080/ [2022-01-11T03:38:43.628Z] info - Authentication is enabled [2022-01-11T03:38:43.628Z] info - Using password from ~/.config/code-server/config.yaml [2022-01-11T03:38:43.628Z] info - Not serving HTTPS [22:38:51] Extension host agent started. [22:38:51] [Theme Service] Scanning for theme extension... [22:38:51] [Theme Service] theme-abyss [22:38:51] [Theme Service] theme-defaults [22:38:51] [Theme Service] theme-kimbie-dark [22:38:51] [Theme Service] theme-monokai [22:38:51] [Theme Service] theme-monokai-dimmed [22:38:51] [Theme Service] theme-quietlight [22:38:51] [Theme Service] theme-red [22:38:51] [Theme Service] theme-solarized-dark [22:38:51] [Theme Service] theme-solarized-light [22:38:51] [Theme Service] theme-tomorrow-night-blue [22:38:51] [Theme Service] Attempting to find user's active theme: Default Dark+ [2022-01-11T03:38:54.949Z] debug got latest version {"latest":"4.0.1"} [2022-01-11T03:38:54.949Z] debug comparing versions {"current":"4.0.1","latest":"4.0.1"} [2022-01-11T03:39:51.007Z] debug 0 active connections

Screenshot

139257954-98741db0-07d2-47f0-a529-fbe57cdd1188 Screen Shot 2022-01-10 at 10 47 35 PM Screen Shot 2022-01-10 at 10 48 36 PM

Notes

I currently only experience this error on code-server 4.0.1. code-server 3.12.0 works without issue. I am currently using apache2 with a reverse proxy. The current config for the apache2 virtual host is below:

<Location "/"> ProxyPass http://127.0.0.1:8080/ ProxyPassReverse http://127.0.0.1:8080/ ProxyPassReverse / RewriteEngine on RewriteCond %{HTTP:Upgrade} websocket [NC] RewriteCond %{HTTP:Connection} upgrade [NC] RewriteRule ^/?(.*) "ws://127.0.0.1:8080/" [P,L]

I also made sure all the websockets modules are loaded in apache2 and working without problems. No errors occur on the Apache web server. Any suggestions on how to get this working with Apache2?

This issue can be reproduced in VS Code: No

lplassman avatar Jan 11 '22 04:01 lplassman

Same issue here. Using apache2 with reverse proxy. Only occur with 4.0.1, code-server 3.12.0 works fine for me.

JimmyNi avatar Jan 12 '22 03:01 JimmyNi

@code-asher any ideas?

jsjoeio avatar Jan 13 '22 16:01 jsjoeio

If the exact same config works with 3.12 that does seem like it could be an issue with 4.0 but I have no idea how; so far all the 1006 errors I have seen have been caused by misconfiguration.

I am not very familiar with Apache but maybe this comment has a clue:

https://github.com/coder/code-server/discussions/2104#discussioncomment-360665

code-asher avatar Jan 13 '22 18:01 code-asher

Same issue here using apache2 with reverse proxy

konni avatar Jan 17 '22 15:01 konni

Ditto.

3.12.0 works fine. 4.0.1 returns 1006. apache2 reverse proxy.

jamieshaw avatar Jan 17 '22 19:01 jamieshaw

Same issue.

sobakaio avatar Jan 19 '22 12:01 sobakaio

Same issue, 3.12.0 works fine and 4.0.1 fails with this error. I'm using apache2 as a reverse proxy. Trying to access the service directly without the proxy seems to work

gmiscione avatar Jan 19 '22 14:01 gmiscione

Sounds like we need to spin up Apache and try to reproduce.

code-asher avatar Jan 19 '22 16:01 code-asher

I found a fix on nginx #4763 not sure if there’s an Apache analog for those settings

dokastho avatar Jan 19 '22 19:01 dokastho

I'm guessing that line from release log "Web socket compression has been made the default (when supported). This means the --enable flag will no longer take permessage-deflate as an option" is causing problem. I tried finding analog to "proxy_set_header Accept-Encoding gzip" nginx but I have not yet figured way to make it work.

siklosi avatar Jan 24 '22 09:01 siklosi

not sure if there’s an Apache analog for those settings

Me neither.

the --enable flag will no longer take permessage-deflate

I cannot find any documentation on said flag, how does it work ? Would there be a --disable flag too, which would allow apache users to upgrade to 4.x ?

KaKi87 avatar Jan 24 '22 09:01 KaKi87

There is no way to disable compression support. It is only used if the browser tells the server that it supports compression.

I am not sure issues with compression could cause a 1006 but you could could try stripping permessage-deflate from the Sec-WebSocket-Extensions header to see if that does anything (this header is how the browser informs the server it supports compression)

code-asher avatar Jan 26 '22 16:01 code-asher

Confirming I was able to reproduce:

$ sudo apt install apache2
$ sudo a2enmod rewrite proxy proxy_http proxy_wstunnel
$ sudo vim /etc/apache2/sites-available/000-default.conf # See below
$ sudo apache2
$ code-server --version
4.0.1 735c6da829535969ff7193c79379299e4a1cb9bc
$ code-server --port 8080
<VirtualHost *:80>
  ProxyPass / http://localhost:8080/
  RewriteEngine on
  RewriteCond %{HTTP:Upgrade} websocket [NC]
  RewriteCond %{HTTP:Connection} upgrade [NC]
  RewriteRule ^/?(.*) "ws://localhost:8080/$1" [P,L]
</VirtualHost>
  1. Open localhost in browser
  2. Get 1006 errors

Then to confirm it is a 4.0.1 issue I killed code-server with C-c and installed 3.12.0 with yarn:

$ yarn global add [email protected]
$ ~/.yarn/bin/code-server --version # .yarn/bin is not in my path
3.12.0 4cd55f94c0a72f05c18cea070e10b969996614d2
$ ~/.yarn/bin/code-server --port 8080
  1. Open localhost in browser (Apache is still running from earlier)
  2. Everything works

code-asher avatar Jan 26 '22 17:01 code-asher

I'm also seeing this bug, with NGINX (using nginx proxy manager). I'm currently trying to fix with https://github.com/coder/code-server/issues/4763 but I'm not having any luck. Latest docker version of code-server.

spenceradolph avatar Feb 01 '22 19:02 spenceradolph

So, will there be a way to disable compression ?

KaKi87 avatar Feb 01 '22 20:02 KaKi87

Update! The problem was resolved when I tried it from an outside network. So it may have something to do with local routing / proxying differences. Unsure if this is directly related, but my websocket 1006 has been resolved. If I'm local and want to test through the domain I have it on, I'll have to figure out something else.

Websocket 1006 error occurred under these conditions.

  • nginxproxymanager to code-server (all in docker-compose) for my subdomain.
  • also exposed code-server to local machine
  • localhost:8080 to code-server works perfectly
  • code.mydomain.com gives 1006 error (tried from same host)
  • code.mydomain.com works perfectly (tried from host outside network)

spenceradolph avatar Feb 02 '22 16:02 spenceradolph

I'm hosting code-server in a dedicated server so I'm definitely in a different network.

KaKi87 avatar Feb 02 '22 17:02 KaKi87

same here. Reverse Proxy with apache. 3.X Versions running fine

chrirauch avatar Feb 03 '22 13:02 chrirauch

Thanks for the comments all! We've recognized this is affecting a lot of people. Instead of commenting, please give the initial issue description a "thumbs-up". Thanks!

jsjoeio avatar Feb 03 '22 19:02 jsjoeio

FYI: I also see some content security policy complaints in console log. There are also some 1006 errors, that are resolved in newer versions https://github.com/microsoft/vscode-remote-release/issues/6031 Although code server works without apache reverse proxy (http, not https), that's not really clever to run though the internet :)

predkambrij avatar Mar 05 '22 20:03 predkambrij