From cf421b7b39e3fbe860a301fbe43e779258418bb1 Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Tue, 7 Jul 2026 18:27:35 +0000 Subject: [PATCH] Enhancement: Refine database connection management in event dispatching and logging functions by conditionally closing old connections based on gevent monkey patching status, improving resource handling during asynchronous operations. --- core/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/utils.py b/core/utils.py index 16d9ed85..c167e6b9 100644 --- a/core/utils.py +++ b/core/utils.py @@ -788,7 +788,8 @@ def dispatch_event_system(event_type, channel_id=None, channel_name=None, **deta # Don't fail main path if connect dispatch fails pass finally: - close_old_connections() + if _should_use_sync_websocket_send() or _is_gevent_monkey_patched(): + close_old_connections() def _dispatch_system_event_integrations( @@ -886,7 +887,8 @@ def log_system_event(event_type, channel_id=None, channel_name=None, **details): finally: # geventpool keeps checked-out connections until close(); release promptly # when logging from proxy greenlets/threads outside a normal request cycle. - close_old_connections() + if _is_gevent_monkey_patched(): + close_old_connections() def _send_async(channel_layer, group, message):