Fix bridge (https://github.com/DMOJ/online-judge/pull/2080)
This commit is contained in:
parent
304fa0e0f3
commit
7d5efa60c7
3 changed files with 13 additions and 6 deletions
|
@ -145,6 +145,9 @@ class ZlibPacketHandler(metaclass=RequestHandlerMeta):
|
||||||
def on_timeout(self):
|
def on_timeout(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def on_cleanup(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def handle(self):
|
def handle(self):
|
||||||
try:
|
try:
|
||||||
tag = self.read_size()
|
tag = self.read_size()
|
||||||
|
@ -204,6 +207,8 @@ class ZlibPacketHandler(metaclass=RequestHandlerMeta):
|
||||||
if e.__class__.__name__ == "cancel_wait_ex":
|
if e.__class__.__name__ == "cancel_wait_ex":
|
||||||
return
|
return
|
||||||
raise
|
raise
|
||||||
|
finally:
|
||||||
|
self.on_cleanup()
|
||||||
|
|
||||||
def send(self, data):
|
def send(self, data):
|
||||||
compressed = zlib.compress(data.encode("utf-8"))
|
compressed = zlib.compress(data.encode("utf-8"))
|
||||||
|
|
|
@ -2,6 +2,8 @@ import json
|
||||||
import logging
|
import logging
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
|
from django import db
|
||||||
|
|
||||||
from judge.bridge.base_handler import Disconnect, ZlibPacketHandler
|
from judge.bridge.base_handler import Disconnect, ZlibPacketHandler
|
||||||
|
|
||||||
logger = logging.getLogger("judge.bridge")
|
logger = logging.getLogger("judge.bridge")
|
||||||
|
@ -60,5 +62,5 @@ class DjangoHandler(ZlibPacketHandler):
|
||||||
def on_malformed(self, packet):
|
def on_malformed(self, packet):
|
||||||
logger.error("Malformed packet: %s", packet)
|
logger.error("Malformed packet: %s", packet)
|
||||||
|
|
||||||
def on_close(self):
|
def on_cleanup(self):
|
||||||
self._to_kill = False
|
db.connection.close()
|
||||||
|
|
|
@ -36,10 +36,7 @@ SubmissionData = namedtuple(
|
||||||
|
|
||||||
|
|
||||||
def _ensure_connection():
|
def _ensure_connection():
|
||||||
try:
|
db.connection.close_if_unusable_or_obsolete()
|
||||||
db.connection.cursor().execute("SELECT 1").fetchall()
|
|
||||||
except Exception:
|
|
||||||
db.connection.close()
|
|
||||||
|
|
||||||
|
|
||||||
class JudgeHandler(ZlibPacketHandler):
|
class JudgeHandler(ZlibPacketHandler):
|
||||||
|
@ -903,3 +900,6 @@ class JudgeHandler(ZlibPacketHandler):
|
||||||
"language": data["language__key"],
|
"language": data["language__key"],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def on_cleanup(self):
|
||||||
|
db.connection.close()
|
||||||
|
|
Loading…
Add table
Reference in a new issue