WebSockets in 1.0

Hello.

I updated to the latest version this week and got a Connection lost error in the interface and pushConnection.ts:96 WebSocket connection to 'wss://n8n.xxx.xx/rest/push?sessionId=xxxxx' failed in the console.

I tried the recommendations from other topics where a similar problem was discussed, but they did not lead to anything. I pointed the domain to the server directly and through Cloudflare, the result is the same. I did not configure anything except nginx and pm2, the server is almost bare.

Also tried to reconfigure the server. I’ve tried DigitalOcean, Hetzner, and separately setting up Docker-Compose from scratch from the documentation. All options lead to the following problem:

Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/root/n8n-docker-caddy/caddy_config/Caddyfile" to rootfs at "/etc/caddy/Caddyfile": mount /root/n8n-docker-caddy/caddy_config/Caddyfile:/etc/caddy/Caddyfile (via /proc/self/fd/6), flags: 0x5000: not a directory: unknown : Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

And advice from the forum also did not give results.

I ended up going back to my pm2 and nginx option - the one listed as my configuration below. I set up a brand new server following the instructions here: https://blog.n8n.io/how-to-set-up-n8n-via-pm2/. And got the same Connection lost error unfortunately. But I went back to N8N_PUSH_BACKEND=sse, which seems to suit me.

Finally my questions. :slight_smile:
Is there a technical advantage to WebSockets? In speed or load on the server?
Is there a plan to deprecate server-sent events in the future and keep only WebSockets?
Is there an up-to-date setup manual that eradicates the problems described above? What can I try now to enable WebSockets?

Thank you.
And thank you for such a great tool. :slight_smile:

  • n8n version: 1.1.1
  • Database (default: SQLite): default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): npm with pm2 and nginx
  • Operating system: Ubuntu 22.04.3 LTS
1 Like

Hey @robprane,

Welcome to the community :tada:

The Caddy error you have looks like an issue in the config although I ran through that setup guide this morning and it is working so I expect it was just the data path that needs correcting.

To answer your questions…

  1. WebSockets allow us to support more deployment types and are generally considered to be better.
  2. WebSockets is the default now and SSE will likely be removed in the future
  3. Any of our deployment guides will work, In your case though if you are using nginx the issue will likely be with your nginx configuration. I use nginx for 2 of my personal installations and it is working without issue, You could however see extra issues if you are also using Cloudflare to cache so it depends on if you see the connection lost error all the time or just occasionally.

A working nginx config is below.

server {
  listen 443 ssl;
  server_name n8n.my_domain.tld;
  location / {
    proxy_pass http://127.0.0.1:5678;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Upgrade $http_upgrade;
    proxy_http_version 1.1;
  }
  ssl_certificate # removed
  ssl_certificate_key # removed
}

I used this nginx config:

server {
    server_name n.<domain>.io;
    location / {
        proxy_pass http://localhost:5678;
        proxy_http_version 1.1;
        proxy_set_header Connection '';
        proxy_set_header Host $host;
        chunked_transfer_encoding off;
        proxy_buffering off;
        proxy_cache off;
    }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/n.rbpn.io/fullchain.pem; # managed by>
    ssl_certificate_key /etc/letsencrypt/live/n.rbpn.io/privkey.pem; # managed >
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

And this Caddyfile in other builds:

n.<domain>.io {
    reverse_proxy n8n:5678 {
      flush_interval -1
    }
}

Can you point out what is causing the error here?

The caddy file is fine assuming you replaced the issue is likely to be the path in the .env file.

For your nginx config try…

server {
    server_name n.<domain>.io;
    location / {
        proxy_pass http://localhost:5678;
        proxy_http_version 1.1;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Upgrade $http_upgrade;
    }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/n.rbpn.io/fullchain.pem; # managed by>
    ssl_certificate_key /etc/letsencrypt/live/n.rbpn.io/privkey.pem; # managed >
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

This nginx config works fine. Thank you!
It might make sense to edit your instructions for pm2.

I couldn’t make friends with Caddy. But at least pm2 works.

Hey @robprane,

We don’t really support pm2 officially so the post has not been updated for a while, I will make a note to see if we plan to do anything with pm2 properly but I think docker is our preferred method as there are no extra things to install.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.