mirror of
https://github.com/jumpserver/jumpserver.git
synced 2026-08-09 08:03:53 +00:00
fix: manage database connections in LDAP worker threads
This commit is contained in:
@@ -60,8 +60,10 @@ def close_old_connections(**kwargs):
|
||||
@contextmanager
|
||||
def safe_db_connection():
|
||||
close_old_connections()
|
||||
yield
|
||||
close_old_connections()
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
close_old_connections()
|
||||
|
||||
|
||||
@contextmanager
|
||||
|
||||
@@ -11,7 +11,7 @@ from django.core.cache import cache
|
||||
from django.utils import translation
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from common.db.utils import close_old_connections
|
||||
from common.db.utils import close_old_connections, safe_db_connection
|
||||
from common.utils import get_logger
|
||||
from orgs.mixins.ws import OrgMixin
|
||||
from orgs.models import Organization
|
||||
@@ -148,8 +148,9 @@ class LdapWebsocket(AsyncJsonWebsocketConsumer, OrgMixin):
|
||||
await self.send_msg(msg='Exception: %s' % error)
|
||||
|
||||
def run_func(self, func_name, data):
|
||||
with translation.override(getattr(self.scope['user'], 'lang') or settings.LANGUAGE_CODE):
|
||||
return getattr(self, func_name)(data)
|
||||
with safe_db_connection():
|
||||
with translation.override(getattr(self.scope['user'], 'lang') or settings.LANGUAGE_CODE):
|
||||
return getattr(self, func_name)(data)
|
||||
|
||||
async def send_msg(self, ok=True, msg=''):
|
||||
await self.send_json({'ok': ok, 'msg': f'{msg}'})
|
||||
|
||||
Reference in New Issue
Block a user