Thank you for the hint, we did pin whitenoise version to 5.3.0, and it indeed solved our random connection errors.
So, there appears to be a relation; however, it is tricky (in our case) to pin down to a certain version/commit/functionality.
I also posted this as an issue in whitenoise repo:
(the only thing - I am struggling to reproduce it outside our production instance)
Just wanted to share that I had this error show up for me today for the first time. I am using whitenoise==6.6.0 It is a bit strange though as I have had this project running for many months now and never experienced any problems before. even now it seems to be only 2 or 3 requests in a thousand
Hello everyone, Iām glad Iām finding this thread, as we are starting to seriously lose our mind here, experiencing the same random issue every couple of requests.
What we have narrowed it down to is: we only see this when running our django app from a Docker container (in either Azure App Service or Azure Container App: the issue happens in both) but never when running the same app on a regular Linux VM without using Docker (just plain gunicorn on Ubuntu server).
Our setup:
Python 3.12
Django 4.2.20
gunicorn 22.0.0
psycopg 3.2.4
Postgres 15 or 16 (tried both) (managed Azure Database for Postgresql Flexible Server)
Both using pgbouncer and without pgbouncer enabled
Now indeed, one difference for us running in a Docker container is that we use django-whitenoise in this situation, and NOT when running on pure Linux VM (where we let nginx serve the assets).
So I am very interested in that clue and will experiment with and without whitenoise.
It is rather hard to debug this due to the very random occurrences of the issue: can happen in any request on any page (including django admin interface) and at any point in the tracebackā¦
If anyone has had a more precise resolution, please share any update you have here!
I confirm that upgrading to whitenoise >= 6.8.0 seems to fix this issue for us. It looks like this very thread here is what alerted them of the issue and got them to fix it: Changelog - WhiteNoise 6.9.0 documentation
We need to monitor our app for a longer period of time after upgrading whitenoise to be more confident this is completely resolved for us.