Back

[SOLVED]Realtime getting disconnected and websocket connection failed

  • 0
  • Realtime
SQUANT
31 Mar, 2023, 13:15

Hey guys, i am using this code to access my database using realtime client.subscribe('databases.[ID].collections.[ID].documents.create', (payload: any) => { console.log(payload) }) I have replaced the [ID] for the corresponding ID i dont know what is the problem.

this is the errors i am getting

WebSocket connection to 'wss:///v1/realtime?project=ID&channels%5B%5D=collections.6406910f7d0377e9d2.documents.create&channels%5B%5D=collections.642607b69f346b1aac6d.documents.create&channels%5B%5D=databases.642607ad8b10bc1f0b79.collections.642607b69f346b1aac6d.documents.create' failed: createSocket @ client.ts:235 (anonymous) @ client.ts:257 client.ts:253 Realtime got disconnected. Reconnect will be attempted in 10 seconds.

TL;DR
The user was experiencing disconnections and websocket connection failures. They were able to solve the issue by adding some lines to their NGINX configuration. The issue was related to the websocket configuration in NGINX and changing the main docker port. They confirmed that the realtime component was running successfully. The user also mentioned that they were able to fetch data from the database but couldn't subscribe. They confirmed that the realtime service was initialized. However, they were still getting errors when trying to access the database using realtime. The TL;DR solution is to check the NGINX configuration, make sure the main docker port and realtime port are correctly configured
Binyamin
31 Mar, 2023, 13:19

Have you initialized the client with the endpoint?

Binyamin
31 Mar, 2023, 13:20
TypeScript
const client = new Client()
    .setEndpoint('https://[HOSTNAME_OR_IP]/v1')
    .setProject('[PROJECT_ID]');
SQUANT
31 Mar, 2023, 13:20

yes, it is initialized

Binyamin
31 Mar, 2023, 13:26

Run docker ps Do you see that realtime is indeed running?

SQUANT
31 Mar, 2023, 13:40

yes, it is running, maybe i should change the running port because i have changed it to traefik?

SQUANT
31 Mar, 2023, 13:43

nope not worked

SQUANT
31 Mar, 2023, 13:44

i can fetch data from the database but i cant subscribe

Binyamin
31 Mar, 2023, 13:48

When you have changed the main docker port, do you also changed the realtime?

TypeScript
  appwrite-realtime:
    image: appwrite/appwrite:1.2.1
    entrypoint: realtime
    container_name: appwrite-realtime
    <<: *x-logging
    restart: unless-stopped
    labels:
      - "traefik.enable=true"
      - "traefik.constraint-label-stack=appwrite"
      - "traefik.docker.network=appwrite"
      - "traefik.http.services.appwrite_realtime.loadbalancer.server.port=80"
      #ws
      - traefik.http.routers.appwrite_realtime_ws.entrypoints=appwrite_web
      - traefik.http.routers.appwrite_realtime_ws.rule=PathPrefix(`/v1/realtime`)
      - traefik.http.routers.appwrite_realtime_ws.service=appwrite_realtime
      # wss
      - traefik.http.routers.appwrite_realtime_wss.entrypoints=appwrite_websecure
      - traefik.http.routers.appwrite_realtime_wss.rule=PathPrefix(`/v1/realtime`)
      - traefik.http.routers.appwrite_realtime_wss.service=appwrite_realtime
      - traefik.http.routers.appwrite_realtime_wss.tls=true
      - traefik.http.routers.appwrite_realtime_wss.tls.certresolver=dns
SQUANT
31 Mar, 2023, 13:56

i have tried changing it but it didnt work

Drake
31 Mar, 2023, 14:31

Do you have a reverse proxy in front of Appwrite?

SQUANT
31 Mar, 2023, 17:49

yes i have, i am using nginx

Drake
31 Mar, 2023, 18:07

is nginx configured for web sockets?

SQUANT
31 Mar, 2023, 19:01

it is fixed now, i have added this lines to nginx, thank you for your help ```

WebSocket configuration

TypeScript
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_read_timeout 86400;```
SQUANT
31 Mar, 2023, 19:02

[SOLVED]Realtime getting disconnected and websocket connection failed

erikkamalov
30 Oct, 2023, 11:37

8

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more