Server Timeouts

If you are processing some heavy calculations on the server you need to check your server timeouts. If it goes beyond the default timeouts your application will stale so as your customers/users.

Last week we were working on bulk upload functionality on the Node.js server. We had to upload 3000 data from CSV - stream through those data, check data existence, store in the database, and send email to the user.

For simplicity, we uploaded only 1000 data but there was no response from the server. It was okay with 200/300 data. We checked the timeout on the browser, there was no response exactly after 1 minute. We had default express timeout - 2 minutes.

We looked over the Nginx server. There was a default Nginx timeout which is 1 minute. We increased the Nginx timeout to 10min.

Again there was 1 min timeout. We researched a bit and found out that it could be with a load balancer. We had a default load balancer timeout - 1 min. We increased it to 10 min. At this time we had a 2-minute server timeout. We knew it was from the express server. We increased the express timeout to 10 minutes.

We tried with 1000 data and this time we got the response. It took almost 4 minutes and 30 seconds to complete the operation. Everything was working.

If an error exists within 1000 data, only those erroneous data would be discarded and others would-be stored. We needed to add a feature to discard all of the data if an error exists even only to single data.

We used transaction for this feature but MongoDB transaction has only 60 seconds of timeout. If the transaction does not complete within 60 seconds MongoDB throws a transaction error. So, we talked with mongo support. We had to pay for their support. They increased the transaction timeout and the operation completed without an error.

If your API execution takes more than the normal time, you need to increase the server timeouts - your framework timeouts, Nginx, load balancer timeouts, and at last database transaction timeouts.

Often timeouts are neglected which results in unwanted errors. So we need to increase timeouts to cover the worst cases.

© Bipin