From 7ed521c3dca929d4459f73ee7ebcefc2da0c0599 Mon Sep 17 00:00:00 2001 From: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com> Date: Wed, 15 Nov 2023 10:03:35 +1100 Subject: [PATCH] Add gc debugging flag to help debug prod thumbnails leak (#3354) * Add gc debugging flag to help debug prod thumbnails leak * Add documentation to the new environment variable * Simplify setting aggregation --- api/conf/asgi.py | 10 ++++++++++ api/conf/settings/logging.py | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/api/conf/asgi.py b/api/conf/asgi.py index 39cf52c8d4b..2efa17b95c3 100644 --- a/api/conf/asgi.py +++ b/api/conf/asgi.py @@ -20,3 +20,13 @@ def get_asgi_application(): if settings.ENVIRONMENT == "local": static_files_application = ASGIStaticFilesHandler(application) + + +if settings.GC_DEBUG_LOGGING: + import gc + + setting = 0 + for flag in settings.GC_DEBUG_LOGGING: + setting |= getattr(gc, flag) + + gc.set_debug(setting) diff --git a/api/conf/settings/logging.py b/api/conf/settings/logging.py index df0979b75f2..a8ae2a842cb 100644 --- a/api/conf/settings/logging.py +++ b/api/conf/settings/logging.py @@ -14,6 +14,12 @@ def health_check_filter(record: LogRecord) -> bool: LOG_LEVEL = config("LOG_LEVEL", default="INFO").upper() DJANGO_DB_LOGGING = config("DJANGO_DB_LOGGING", cast=bool, default=False) +# Set to a pipe-delimited string of gc debugging flags +# https://docs.python.org/3/library/gc.html#gc.DEBUG_STATS +GC_DEBUG_LOGGING = config( + "GC_DEBUG_LOGGING", cast=lambda x: x.split("|") if x else [], default="" +) + # https://github.com/dabapps/django-log-request-id#logging-all-requests LOG_REQUESTS = True