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

The workbench failed to connect to the server (Error: WebSocket close with status code 1006)

Open isolume opened this issue 5 years ago • 46 comments

OS/Web Information

  • Web Browser: Chromium (brave), although I also tested with Firefox and Edge and got the same result.
  • Local OS: Windows 11
  • Remote OS: Ubuntu
  • Remote Architecture: x86-64
  • code-server --version: 3.12.0

Steps to Reproduce

  1. Ran code-server (i also tried using --proxy-domain to see if I got any different results.) I used nginx to reverse proxy to my domain, I also use Cloudflare.
  2. When I open the domain on my browser, I get
The workbench failed to connect to the server (Error: WebSocket close with status code 1006)

Expected

The server would work normally.

Actual

See error above.

Logs

Logs look normal for the remote server, however browser gives error:

[vscode] failed to initialize VS Code vscode.browserified.js:726:13
    [4]< <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:726
    o <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:1
    r <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:1
    <anonymous> <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:1

(I replaced my domain with for privacy reasons.)

Error: [vscode] Could not set body background to theme background color. Could not find colorThemeData in localStorage.
    setBodyBackgroundToThemeBackgroundColor <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:668
    main <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:719
    [4]< <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:723
    o <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:1
    r <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:1
    <anonymous> <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:1
vscode.browserified.js:727:13
    [4]< <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:727
    o <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:1
    r <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:1
    <anonymous> <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:1

Screenshot

image

Notes

This issue can be reproduced in VS Code: No

isolume avatar Nov 04 '21 00:11 isolume

i got this too. i ran it in docker. i found there must be lines below in the nginx.conf to make it work location / { proxy_pass http://codeserver.xxx.xxx:8443/; proxy_set_header Host $host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection upgrade; proxy_set_header Accept-Encoding gzip; } this is from https://github.com/cdr/code-server/blob/main/docs/guide.md#using-lets-encrypt-with-nginx

woshilaiba avatar Nov 04 '21 09:11 woshilaiba

proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection upgrade; proxy_set_header Accept-Encoding gzip;

Thanks, that seemed to work.

isolume avatar Nov 04 '21 16:11 isolume

Any idea which version broke this? I can't get it to work with Nginx-Proxy-Manager so I'll just downgrade until code-server gets it's sh*t together.

bobbywaz avatar Nov 13 '21 23:11 bobbywaz

cc @code-asher

jsjoeio avatar Nov 15 '21 21:11 jsjoeio

Those headers enable proxying websockets so it is not a code-server issue as far as I can tell.

code-asher avatar Nov 16 '21 16:11 code-asher

If anyone is looking for a solution for ingress-nginx on Kubernetes like I was, add this annotation to your ingress

nginx.org/websocket-services: "code-server"

Replace code-server with whatever your code-server service name is.

bsmithio avatar Nov 29 '21 06:11 bsmithio

A little late now, but does anyone have a working configuration for Apache2?

ZandercraftGames avatar Feb 06 '22 20:02 ZandercraftGames

A little late now, but does anyone have a working configuration for Apache2?

Hey looking for the same thing, having issues proxying code server in apache2

tinuh avatar Feb 26 '22 22:02 tinuh

When adding the domain or subdomain for code-server on Nginx Proxy Manager make sure to check the Websockets support to solve the problem. Screenshot-2022-03-25-175109

AuthorShin avatar Mar 25 '22 13:03 AuthorShin

@tinuh @ZandercraftGames For those having issues with reverse proxy in Apache, refer to https://github.com/coder/code-server/issues/4723#issuecomment-1105319574

I hope this works for you!

leuit avatar Apr 21 '22 16:04 leuit

A little late now, but does anyone have a working configuration for caddy2?

1m188 avatar Apr 26 '22 16:04 1m188

proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection upgrade; proxy_set_header Accept-Encoding gzip;

Thank you very much. It's very useful to me.

bravo-wd avatar Jun 08 '22 03:06 bravo-wd

for kubernetes, I had to add BOTH suggestions from Link1 and annotations as follows.

PS: the {{ .Values.user }} etc, are dynamic values from values.yml of helm chart which you need to replace

    nginx.org/websocket-services: code-server-{{ .Values.user }}
    nginx.org/server-snippets: |
      location / {
      proxy_pass http://{{ .Values.host_domain }}:{{ .Values.port }}/;
      proxy_set_header Host $host;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection upgrade;
      proxy_set_header Accept-Encoding gzip;
      }  

Entire example below using helm chart

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: code-server-{{ .Values.user }}
  namespace:  {{ .Values.namespace }}
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.org/websocket-services: code-server-{{ .Values.user }}
    nginx.org/server-snippets: |
      location / {
      proxy_pass http://{{ .Values.host_domain }}:{{ .Values.port }}/;
      proxy_set_header Host $host;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection upgrade;
      proxy_set_header Accept-Encoding gzip;
      }   
spec:
  tls:
  - hosts:
    - {{ .Values.host_domain }}
    secretName: code-server-secret-{{ .Values.user }}
  rules:
  - host: {{ .Values.host_domain }}
    http:
      paths:
      - pathType: Prefix
        path: "/"
        backend:
          service:
            name: code-server-{{ .Values.user }}
            port:
              number: {{ .Values.port }}

getkub avatar Jun 12 '22 10:06 getkub

Hello, leaving this comment here just in case anyone in the future is having this issue.

Cloudflare tunnels, got this same error. Solution was going to dash.cloudflare.com and setting websockets to enabled

image

jeremy-code avatar Sep 01 '22 15:09 jeremy-code

When adding the domain or subdomain for code-server on Nginx Proxy Manager make sure to check the Websockets support to solve the problem. Screenshot-2022-03-25-175109

This worked Thank you. I was having trouble with error on OpenBooks and this fixed that to.

type0dev avatar Nov 06 '22 16:11 type0dev

A little late now, but does anyone have a working configuration for caddy2?

Did you ever get a resolution to this?

smseidl avatar Dec 09 '22 14:12 smseidl

If you are facing wss:// websocket 1006 error on kubernetes with NGINX Ingress Controller, you can try to add timeout annotations to service ingress.

nginx.org/proxy-read-timeout: "3600"
nginx.org/proxy-send-timeout: "3600"

janisii avatar Dec 28 '22 12:12 janisii

I don't want to wake up an old issue. But I've had it working, and suddenly this error came. I'm using swag and my reverse proxy conf was working fine. The suggested addition of headers didn't work. Any tips?

keesfluitman avatar Mar 23 '23 21:03 keesfluitman

Just to confirm, is Host one of the headers you added? v4.10.0 added a security check that uses the host and origin headers.

code-asher avatar Mar 27 '23 16:03 code-asher

@code-asher thanks. Adding Host solved the issues with v4.12.0.

mturilli avatar Apr 28 '23 18:04 mturilli