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

[question] Using Centrifugo-js in backend side (Websocket) #665

Closed
sajjad-fatehi opened this issue Jun 10, 2023 · 2 comments
Closed

[question] Using Centrifugo-js in backend side (Websocket) #665

sajjad-fatehi opened this issue Jun 10, 2023 · 2 comments

Comments

@sajjad-fatehi
Copy link

sajjad-fatehi commented Jun 10, 2023

hi :)
we are using centrifugo-js in our back-end application for rpc, join/leave, publish , ...
but in peak times on our application our web-scoket connection from back-end to centrifugo server is disconnecting and reconnecting .

What does "reason" means ins this error message:
disconnect context : the reason is connection closed and reconnect is true

  • Is it okay to use web-socket as a protocol to communicate with centrifugo (instead of API) ?
  • How we can debug this issue (any suggestions) ?
  • How can we determine the reason for closing the connection?

thank you

@FZambia
Copy link
Member

FZambia commented Jun 10, 2023

Hello, using client SDK on the backend side may work - but it's not a scalable approach if you want to consume many channels and many messages. The idiomatic way to integrate with Centrifugo is outlined in the documentation. App users connect over real-time SDKs, backend uses server API to communicate with Centrifugo.

Trying to answer the questions:

what is the of this reason meaning ?

connection closed may be any network issue - it's actually a default reason when no other specific code received from the server in close handshake. Probably your connection is too slow and Centrifugo dropped it - in this case you may find this information in server debug logs and in disconnect code Prometheus metrics.

is it okay to use web-socket as a protocol to communicate with centrifugo (instead of API) ?

As said above - it may work for basic cases, but does not scale and may quickly become a bottleneck. Real-time SDKs exist for the application users with a reasonable message rate, not for the backend.

how we can debug this issue (any suggestions ) ?

You can try to find a reproducer, then isolate the root cause step by step. Think why the connection may be closed - it involves log inspection, understanding message volume. I'd start with server logs. If the connection is closed during "peak" hours as you mentioned - then it possibly can not keep up with the incoming message rate.

You can also take centrifuge-js and try to log WebSocket transport close code - https://github.com/centrifugal/centrifuge-js/blob/047301dc7368c62ee34e0d8be0f3a3e638eb3598/src/centrifuge.ts#L801, we are not exposing it in the SDK API directly - probably it will contain something useful which will point you to some problem.

@sajjad-fatehi
Copy link
Author

thanks a lot 😍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants