Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flask application timeout with amazon load balancer

I'm trying to use a Flask application behind an Amazon Load Balancer and the Flask threads keep timing out. It appears that the load balancer is sending a Connection: keep-alive header and this is causing the Flask process to never return (or takes a long time). With gunicorn in front the processes are killed and new ones started. We also tried using uWSGI and simply exposign the Flask app directly (no wrapper). All result in the Flask process just not responding.

I see nothing in the Flask docs which would make it ignore this header. I'm at a loss as to what else I can do with Flask to fix the problem.

Curl and direct connections to the machine work fine, only those via the load balancer are causing the problem. The load balancer itself doesn't appear to be doing anything wrong and we use it successfully with several other stacks.

like image 711
edA-qa mort-ora-y Avatar asked May 08 '13 15:05

edA-qa mort-ora-y


People also ask

What is AWS load balancer idle timeout?

By default, Elastic Load Balancing sets the idle timeout value for your load balancer to 60 seconds. Use the following procedure to set a different idle timeout value. To update the idle timeout value using the console. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/ .

Does AWS ELB support sticky session?

If you are using multiple layers of Application Load Balancers, you can enable sticky sessions across all layers with application-based cookies. However, with duration-based cookies, you can enable sticky sessions only on one layer, because AWSALB is the only name available.

Can you use flask with AWS?

Complete the following prerequisites before you get started with your Flask app. 1.1 — You need an AWS account and must install Docker, the AWS Command Line Interface (CLI) tool and the Lightsail Control (lightsailctl) plugin on your system. Follow the provided links if you don't have some of those.


1 Answers

The solution I have now is using gunicorn as a wrapper around the flask application. For the worker_class I am using eventlet with several workers. This combination seems stable and responsive. Gunicorn is also configured for HTTPS.

I assume it is a defect in Flask that causes the problem and this is an effective workaround.

like image 132
edA-qa mort-ora-y Avatar answered Sep 22 '22 00:09

edA-qa mort-ora-y