mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-07-22 17:48:09 +00:00
This update addresses issues related to geventpool database connection leaks by consistently invoking `close_old_connections()` in `finally` blocks within the backup scheduler, plugin repository refresh, and core notification synchronization processes. These changes ensure that idle connections are properly released, preventing resource exhaustion. HLS proxy server has been disabled (hasn't been used). Additionally, the proxy server cleanup logic has been enhanced to safely handle the absence of proxy instances. Tests have been updated to validate these improvements and ensure stability in high-load scenarios.
50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
from django.apps import AppConfig
|
|
from django.conf import settings
|
|
import logging
|
|
|
|
# Define TRACE level (5 is below DEBUG which is 10)
|
|
TRACE = 5
|
|
logging.addLevelName(TRACE, "TRACE")
|
|
|
|
# Add trace method to the Logger class
|
|
def trace(self, message, *args, **kwargs):
|
|
"""Log a message with TRACE level (more detailed than DEBUG)"""
|
|
if self.isEnabledFor(TRACE):
|
|
self._log(TRACE, message, args, **kwargs)
|
|
|
|
# Add the trace method to the Logger class
|
|
logging.Logger.trace = trace
|
|
|
|
|
|
class CoreConfig(AppConfig):
|
|
default_auto_field = 'django.db.models.BigAutoField'
|
|
name = 'core'
|
|
|
|
def ready(self):
|
|
# Import signals to ensure they get registered
|
|
import core.signals
|
|
from dispatcharr.app_initialization import should_skip_initialization
|
|
|
|
# Sync developer notifications and check for version updates on startup
|
|
# Only run in the main process (not in management commands, migrations, or workers)
|
|
if should_skip_initialization():
|
|
return
|
|
|
|
self._sync_developer_notifications()
|
|
|
|
def _sync_developer_notifications(self):
|
|
"""Sync developer notifications from JSON file to database."""
|
|
from django.db import close_old_connections
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
try:
|
|
from core.developer_notifications import sync_developer_notifications
|
|
sync_developer_notifications()
|
|
except Exception as e:
|
|
logger.warning(f"Failed to sync developer notifications on startup: {e}")
|
|
finally:
|
|
# Boot ORM runs outside a request cycle; return geventpool checkouts.
|
|
close_old_connections()
|
|
|