0

I have a node.js backend that does operations that take over a minute to complete and the result of these operations is returned to the user.

This node.js application is behind an aws load balancer, which has a timeout of 60 seconds (I cannot change it) so when the user does an api call to my backend, the operation takes over 60 seconds so the load balancer times out as the connection was idle for too long.

My question: is it possible for the backend to send some sort of information/packets back to the user every 30 seconds, so the connection is not considered idle?

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
makukas
  • 5
  • 3
  • Does this help https://stackoverflow.com/questions/20210522/nodejs-mysql-error-connection-lost-the-server-closed-the-connection – Jatin Mehrotra Sep 01 '20 at 07:52

1 Answers1

0

The timeouts are there for preserving server and intermediary resources mainly.

Consider the following timeouts -

  1. Connection Timeout - The time a client has to wait until the connection is made

  2. Socket Timeout - How long a connection can be idle without data

  3. Request Timeout - How long the fulfillment of a request should take

Even though you can fight off the 2nd type of timeout by periodically sending data to the client, you cannot overcome the 3rd type which maybe even imposed by intermediary gateways or proxies.

So, rather than planning on flavoring the connection with periodic data, go for HTTP polling. In short, your server can take the request, initiate the long process, issue a token and end the connection. The clients can poll with the token and get the processed data when done.

Charlie
  • 22,886
  • 11
  • 59
  • 90