fix: 修复数据库连接没有关闭的问题

v2.14
ibuler 2021-11-18 16:04:09 +08:00 committed by Jiangjie.Bai
parent ed408fb739
commit eb75a468ed
1 changed files with 4 additions and 0 deletions

View File

@ -2,6 +2,7 @@ import threading
import json
from redis.exceptions import ConnectionError
from channels.generic.websocket import JsonWebsocketConsumer
from django.db import close_old_connections
from common.utils import get_logger
from .site_msg import SiteMessageUtil
@ -65,8 +66,11 @@ class SiteMsgWebsocket(JsonWebsocketConsumer):
logger.debug('Decode json error: ', e)
except ConnectionError:
logger.debug('Redis chan closed')
finally:
close_old_connections()
def disconnect(self, close_code):
if self.chan is not None:
self.chan.close()
self.close()
close_old_connections()