Explicitly close old DB connections in worker threads before making DB calls
Categories
(Tecken :: Upload, task, P2)
Tracking
(Not tracked)
People
(Reporter: bdanforth, Assigned: bdanforth)
References
Details
(Whiteboard: [cringe])
Attachments
(1 file)
As a follow-up to Bug 1990061.
Django’s CONN_MAX_AGE and CONN_HEALTH_CHECKS only apply to DB connections in the request thread. Since we’re using separate worker threads to upload files in parallel for each upload request, and since each thread maintains their own DB connection, we need to explicitly guard the connection at task boundaries by calling close_old_connections() before doing DB work in the thread.
from django.db import close_old_connections
close_old_connections()
| Assignee | ||
Updated•1 month ago
|
| Assignee | ||
Updated•1 month ago
|
Updated•1 month ago
|
Comment 1•1 month ago
|
||
I had a quick look at the Django source code. I think enabling health checks is all we need. Every change made to the database requests a cursor from database connection object, and enabling health checks makes sure the connection is checked before returning the cursor. This happens regardless of whether the connection is held by the main thread or any other thread.
| Assignee | ||
Comment 2•1 month ago
|
||
| Assignee | ||
Comment 3•1 month ago
|
||
| Assignee | ||
Comment 4•1 month ago
|
||
I've verified this in stage. Given that it's Friday afternoon in my timezone, and I'm out on Monday, I'll plan to deploy this to production when I return on Tuesday, 2025-09-30. I'll add a comment here once it's deployed and (hopefully) verified at that time.
| Assignee | ||
Comment 5•26 days ago
|
||
This was deployed in v2025.09.30. I've verified it in prod, so I'm going to close this out.
Description
•