JLCDev
JLCDev

Reputation: 629

how to use socket.io through google load balancing

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

Upvotes: 7

Views: 1383

Answers (1)

Kalana Demel
Kalana Demel

Reputation: 3266

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:

  • GO TO THE LOAD BALANCING PAGE
  • Select the Edit pencil for your load balancer.
  • Select Backend configuration.
  • Select the Edit pencil for the Backend service.
  • On the line for Protocol, Port, and Timeout settings, select the Edit pencil.
  • Enter a new Timeout Setting in seconds.
  • Click the Update button for the load balancer.

Upvotes: 2

Related Questions