Django ORM sporadically dies when ran in fastAPI endpoints using gunicorn
I'm using the django ORM outside of a django app, in async fastapi endpoints that I'm running with gunicorn.
All works fine except that once in a blue moon I get these odd errors where a worker seemingly "goes defunct" and is unable to process any requests due to database connections dropping.
I've attached a stack trace bellow but they really make no sense whatsoerver to me.
I'm using postgres without any short timeouts (database side) and the way I setup the connectiong enables healthchecks at every request, which I'd assume would get rid of any "stale connection" style issues:
DATABASES = {
"default": dj_database_url.config(
default="postgres://postgres:pass@localhost:5432/db_name",
conn_max_age=300,
conn_health_checks=True,
)
}
I'm curious if anyone has any idea as to how I'd go about debugging this? It's really making the django ORM unusable due to apps going down spontanously.
Stacktrace bellow is an example of the kind of error I get here: