Too Many Open Files error on Django 4.1.1

I upgraded from Django 3.2.15 the latest on the 4.1.x branch, especially to get constraint validation. However, I’m getting a blizzard of OSError Too many open files. I’ve tried bumping the file limit to no effect.

Finally, I downgraded to 3.2.15 and the site runs smoothly once more. I’ve tried running on Gunicorn 20.0.4 & 20.1.0, with Uvicorn worker, configured like so:

import multiprocessing
import gc

bind = '127.0.0.1:1517'
backlog = 1024
cpu_count = multiprocessing.cpu_count()

workers = cpu_count if cpu_count < 8 else 8
worker_connections = 25
worker_class = 'uvicorn.workers.UvicornWorker'
threads = cpu_count
preload_app = True
timeout = 30
keepalive = 2
max_requests = 2000
max_requests_jitter = 200

I’ve not done anything with async ORM or views in 4.1, but I can’t downgrade permanently to 3.2 because I’ve extensively updated the code to take advantage of the constraint validation.

Has something changed about connection handling in 4.1?

1 Like

I found the cause; I needed to update uvicorn. :man_facepalming:

Did you find which change in uvicorn was responsible? I looked quickly in the changelog and couldn’t tell: uvicorn/CHANGELOG.md at master · encode/uvicorn · GitHub