Hello!
Stack:
An AWS load balancer sends traffic to the Ubuntu instance(k8s cluster), which is handled by Nginx, which forwards on to Django (4.0.3) running in gunicorn (19.9.0). Django connects to the database using psycopg2 (2.8.6).
The issue I have is that the database connection seems to shut down randomly. Django reports errors like this:
Postgresql does not report any major errors: I can only assume that the connection was closed correctly and Django was not expecting it.
This happens quite rarely, but enough to be a concern: once every 3 days.
Any suggestions of how to investigate this further would be gratefully accepted. Thanks in advance!
Michele,
> ... the database connection seems to shut down randomly.
Could be the same problem as I described in
Database "InterfaceError connection already closed" with asgi.
https://groups.google.com/g/django-users/c/RmtFuCVLfPE/m/dBQjq7FsBQAJ
Django doesn't stick to the same thread (sync_to_async with
thread_sensitive=False) when generating a response for exceptions. I
haven't studied Django internals, but it seems that it might be better
to use thread_sensitive=True and try to keep using the database
connection prepared for the current request in the current thread.
Regards,
Peter Wagemans