Skip to content

Commit

Permalink
Fix bridge (DMOJ/online-judge#2080)
Browse files Browse the repository at this point in the history
  • Loading branch information
cuom1999 committed Dec 27, 2022
1 parent 304fa0e commit 7d5efa6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
5 changes: 5 additions & 0 deletions judge/bridge/base_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ def on_disconnect(self):
def on_timeout(self):
pass

def on_cleanup(self):
pass

def handle(self):
try:
tag = self.read_size()
Expand Down Expand Up @@ -204,6 +207,8 @@ def handle(self):
if e.__class__.__name__ == "cancel_wait_ex":
return
raise
finally:
self.on_cleanup()

def send(self, data):
compressed = zlib.compress(data.encode("utf-8"))
Expand Down
6 changes: 4 additions & 2 deletions judge/bridge/django_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import logging
import struct

from django import db

from judge.bridge.base_handler import Disconnect, ZlibPacketHandler

logger = logging.getLogger("judge.bridge")
Expand Down Expand Up @@ -60,5 +62,5 @@ def on_disconnect_request(self, data):
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()
8 changes: 4 additions & 4 deletions judge/bridge/judge_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@


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):
Expand Down Expand Up @@ -903,3 +900,6 @@ def _post_update_submission(self, id, state, done=False):
"language": data["language__key"],
},
)

def on_cleanup(self):
db.connection.close()

0 comments on commit 7d5efa6

Please sign in to comment.