Skip to content

(fix) Celery DB pool cleanup#2872

Merged
Uxio0 merged 1 commit intomainfrom
fix-celery-pool
Apr 27, 2026
Merged

(fix) Celery DB pool cleanup#2872
Uxio0 merged 1 commit intomainfrom
fix-celery-pool

Conversation

@Uxio0
Copy link
Copy Markdown
Member

@Uxio0 Uxio0 commented Apr 27, 2026

Summary

This change fixes the production regression introduced by the Celery DB pool cleanup work and hardens startup behavior around gevent.

The root cause was an import side effect chain in the config package:

gunicorn.conf.py -> config.gunicorn -> config.init -> config.celery_app

That caused the web pod to import Celery code before Gunicorn’s gevent worker had applied monkey patching. The new task_postrun cleanup in config.celery_app imported django.db, and under gevent that led to Django DB connections being created/closed under
mismatched thread identities in web requests.

Changes

  • Removed the eager Celery import from config/init.py
  • Kept the Celery task_postrun DB connection cleanup, but made the django.db import lazy inside the signal handler
  • Added regression tests covering:
    • importing config.celery_app does not import django.db
    • the Celery post-task cleanup still closes non-atomic DB connections

Why

  • Web startup should not import the Celery app as a package side effect
  • Reusable modules like config.celery_app should not mutate process-global settings at import time
  • Celery connection cleanup is still needed for gevent workers, but it must not affect the web pod import path

Closes PLA-1366

@Uxio0 Uxio0 merged commit b2405d4 into main Apr 27, 2026
8 checks passed
@Uxio0 Uxio0 deleted the fix-celery-pool branch April 27, 2026 14:27
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants