We are having some problems when trying to connect socket.io
to a node.js
compute engine
instance through google load balancing
.
If I connect from my browser directly to the external IP
of my node.js
everything works fine.
If I try to connect to this same node.js
through the load balancing
(which will be the production architecture), the socket
keeps disconnecting all the time.
We tried to configure Load Balancing with sessionAffinity without success.
Any tips? Thanks
Google's global load balancer knows where the clients are located and directs packets to the closest web service, providing low latency to users while using a single virtual IP (VIP). Using a single VIP means we can increase the time to live (TTL) of our DNS records, which further reduces latency.
Socket.IO allows bi-directional communication between client and server. Bi-directional communications are enabled when a client has Socket.IO in the browser, and a server has also integrated the Socket.IO package. While data can be sent in a number of forms, JSON is the simplest.
By Default The timeout set for http load balancing is 30 seconds by default (Source), this applies to web sockets which in turn is used by socket.io when the protocol is supported by the back-end. Therefore you need to do the following to increase the time out (Source).
To configure the timeout setting:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With