Skip to content

check_disk_space periodic task should db.close_old_connections() after running #352

Description

@medihack

The pattern is already established elsewhere in adit.core.tasks and adit.mass_transfer.tasks (linked to procrastinate-org/procrastinate#1106). check_disk_space queries DicomFolder.objects.all() and currently doesn't close the connection at the end, leaking a Django per-thread connection into the asgiref sync_to_async worker thread.

In production it accumulates over time; in tests it contributes to the test-DB-teardown warning addressed by openradx/adit-radis-shared#197.

Proposed fix

from django import db

@app.periodic(cron="0 7 * * *")
@app.task
def check_disk_space(*args, **kwargs):
    try:
        # ... existing body ...
    finally:
        db.close_old_connections()

Same try/finally pattern as the other ADIT tasks that link to procrastinate#1106.

Audit

A grep across adit/*/tasks.py to catch any other periodic or task functions using ORM without db.close_old_connections() would be worthwhile while addressing this one.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions