This commit is contained in:
cuom1999 2022-12-27 13:19:02 -06:00
parent 304fa0e0f3
commit 7d5efa60c7
3 changed files with 13 additions and 6 deletions

View file

@ -145,6 +145,9 @@ class ZlibPacketHandler(metaclass=RequestHandlerMeta):
def on_timeout(self):
pass
def on_cleanup(self):
pass
def handle(self):
try:
tag = self.read_size()
@ -204,6 +207,8 @@ class ZlibPacketHandler(metaclass=RequestHandlerMeta):
if e.__class__.__name__ == "cancel_wait_ex":
return
raise
finally:
self.on_cleanup()
def send(self, data):
compressed = zlib.compress(data.encode("utf-8"))

View file

@ -2,6 +2,8 @@ import json
import logging
import struct
from django import db
from judge.bridge.base_handler import Disconnect, ZlibPacketHandler
logger = logging.getLogger("judge.bridge")
@ -60,5 +62,5 @@ class DjangoHandler(ZlibPacketHandler):
def on_malformed(self, packet):
logger.error("Malformed packet: %s", packet)
def on_close(self):
self._to_kill = False
def on_cleanup(self):
db.connection.close()

View file

@ -36,10 +36,7 @@ SubmissionData = namedtuple(
def _ensure_connection():
try:
db.connection.cursor().execute("SELECT 1").fetchall()
except Exception:
db.connection.close()
db.connection.close_if_unusable_or_obsolete()
class JudgeHandler(ZlibPacketHandler):
@ -903,3 +900,6 @@ class JudgeHandler(ZlibPacketHandler):
"language": data["language__key"],
},
)
def on_cleanup(self):
db.connection.close()