Closed Bug 1990607 Opened 1 month ago Closed 26 days ago

Explicitly close old DB connections in worker threads before making DB calls

Categories

(Tecken :: Upload, task, P2)

Tracking

(Not tracked)

RESOLVED FIXED

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: nobody → bdanforth
Priority: -- → P2
See Also: → 1990061
Whiteboard: [cringe]

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.

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.

This was deployed in v2025.09.30. I've verified it in prod, so I'm going to close this out.

Status: NEW → RESOLVED
Closed: 26 days ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: