question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

After a while, the server dies ECONNREFUSED

See original GitHub issue

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn’t find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google “How to X in FastAPI” and didn’t find any information.
  • I already read and followed all the tutorial in the docs and didn’t find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

None

Description

I launch fastapi with this command: uvicorn main:app --host 0.0.0.0 --port 17010 --workers 16, and it contains a bunch of endpoints, declared as sync which are passed to Celery and immediately returns, and then Celery does the heavy load.

It has received so far for example approx 100 requests per second, every request looks all alike (same task different parameters), and it works very well and fast. The machine resource consumption is low and everything seems going fine. However, after a few hours, suddenly fastapi stops responding forever: every call is immediately rejected with ECONNREFUSED like it isn’t even listening to the port anymore.

Facts:

  • I can see in the taskmanager that the uvicorn process is still running
  • I can see in the taskmanager that the 16 processes spawned are still running
  • In the uvicorn log, the last line is the last successful request, then nothing
  • In the fastapi log, the last line is the last successful request with some other info from celery, then nothing
  • The machine has still low resources consumption when it happens
  • If I kill all the 17 processes and restart uvicorn, it works as usual
  • Always after a few hours it dies again
  • There are no weird events in the Windows Event Viewer

I have no clue about what is happening and why I can’t see any crash in the logs. How could I find out more?

Operating System

Windows

Operating System Details

Windows Server 2019, 16 cores, 64GB ram

FastAPI Version

0.63.0

Python Version

3.8.8

Additional Context

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
researcher2commented, Sep 11, 2021

We’ve had it running stable on gunicorn since a bit after my last comment, looks like you simply can’t use uvicorn directly for production.

On Sat, Sep 11, 2021 at 1:29 AM STeve Shary @.***> wrote:

@gygabyte017 https://github.com/gygabyte017 Sorry for the slow response. By large file inputs, I mean uploading a large file. I’m not sure what is the root cause of the problem. I suspect that it is not a FastAPI issue, but rather something with Uvicorn. The way that the connections will work is that they will go from your machine to the server. Then the server kernel will route to Uvicorn. Then Uvicorn will route to a FastAPI instance.

The fact that you get a ECONNREFUSED indicates that the server will not setup a TCP connection to even begin to talk to Uvicorn/FastAPI. It sounds like @researcher2 https://github.com/researcher2 does not face that issue when using nginx which further makes me think that uvicorn has something going on.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tiangolo/fastapi/issues/3700#issuecomment-916992497, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHULRU24XMY4JBQUJEL42I3UBIP6TANCNFSM5CDW52OA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

0reactions
github-actions[bot]commented, Nov 18, 2022

Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix ECONNREFUSED – connection refused by server ...
Here's how to do so on Windows: Press the Windows key on your keyboard and type in Control Panel.
Read more >
ECONNREFUSED - Connection refused by the server
This error indicates that the user is trying to connect to your server and is unable to connect to the port. There are...
Read more >
node.js Error: connect ECONNREFUSED; response from server
From your code, It looks like your file contains code that makes get request to localhost (127.0.0.1:8000). The problem might be you have ......
Read more >
Connection dies with ECONNREFUSED - Google Groups
The "random disconnects" is another issue, if it is as issue at all. Node will disconnect sockets to the remote server when they...
Read more >
Connect ECONNREFUSED after Mongod community 6.0 ...
First, check if the old version is still there and running. then stop it. If there is no running server, even trying to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found