How to ignore idle timeout from AWS ELB in the browser


I have an application where a user can upload a PDF using angular-file-upload.js

This library does not support file chunking:

My elastic load balancer is configured to have an idle timeout of 10 seconds and other parts of the application depend on keeping this parameter.

The issue is if the file upload takes longer than 10 seconds the user receives a 504 Gateway Timeout in the browser and an error message. However, the file still reaches the server after some time.

How can I ignore or not show the user this 504 Gateway Timeout that comes from the ELB? Is there another way around this issue?


The issue you have is that an ELB is always going to close the connection unless it gets some traffic back from your server. See below from AWS docs. It’s the same behaviour for an ALB or a Classic load balancer.

By default, Elastic Load Balancing sets the idle timeout to 60 seconds
for both connections. Therefore, if the instance doesn’t send some
data at least every 60 seconds while the request is in flight, the
load balancer can close the connection. To ensure that lengthy
operations such as file uploads have time to complete, send at least 1
byte of data before each idle timeout period elapses, and increase the
length of the idle timeout period as needed.

So to get around this, you have two options:

  1. Change the server processing to start sending some data back as soon as the connection is established, on an interval of less than 10 seconds.
  2. Use another library for doing your uploads, or use vanilla javascript. There are plenty of examples out there, e.g. this one.

Edit: Third option
Thanks to @colde for making the valid point that you can simply work around your load balancer altogether. This has the added benefit of freeing up your server resources which get tied up with lengthy uploads. In our implementation of this we used pre-signed urls to securely achieve this.

Leave a Reply