gunicorn
gunicorn copied to clipboard
gunicorn not response when there is a lot of CLOSE_WAIT tcp connection
I use gunicorn + flask + nginx to deploy my application. Sometime the gunicorn got stuck, but very seldom. There is not any error logs for applications and gunicorn when it got stuck, and, it will get a lot timeout error in http client. I got this problem today, I check the tcp connect status by lsof, I found there is a lot of CLOSE_WAIT connections even reach 1340. I think this problem is cause by the CLOSE_WAIT connections takes up all the tcp resources. How can I resolve this issue? Is it bug of gunicorn?
Sorry about that, I don't know how to reproduct this issue yet, just happen when I try to get some request through http, I just got this issue about 3 time this year. I will try to find the method to reproduct this issue.
gunicorn version is 20.0.4
Hi I also faced this issue, did you find any solutions?
Hi I also faced this issue, did you find any solutions?
Nope. And, still can not reproduct this issue.
I had a similar issue. Gunicorn uses sync
workers by default. I switched to gthread
and experimented with my worker count until the issue went away.
UPDATE: After some more reading, I learned that the async (gthread) workers deliberately leave the TCP connection open, to avoid having to renegotiate new connections. Since this is not what I need, I switched back to sync and found the right number of workers to handle my loads. Turns out that a slow network or client can really effect service. To get around these situations, output from Gunicorn should be buffered by a reverse proxy that sits in front of it.
Face the same issue
Since a week now we're also facing same issue.
Our stack is deployed on AWS Elastic beanstalk with django+gunicorn+nginx
We tried switching to Apache httpd, but after few days encountered the same issue. Lot of connections are in close_wait state.
Can you share the configuration and version of nginx?
Face the same issue, and the bug can easily reproduce with the following settings:
- set threads(like 2) <= worker_connections(like 3)
- just set worker num=1, and worker_type=gthread
- continuously launch 2 clients to send request to the server. Up to now, everything OK
- than launch the 3rt client, the server hangs there. ctrl+c the 3rt client, then we can see CLOSE_WAIT in the output of "lsof -i"