From 34756c399d9f2a187c974467970affedf1db8c4c Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Wed, 15 Nov 2023 08:17:48 -0600 Subject: [PATCH] Handle vanished submission --- judge/bridge/judge_handler.py | 17 ++++++++++++----- judge/bridge/judge_list.py | 4 ++++ judge/bridge/utils.py | 2 ++ 3 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 judge/bridge/utils.py diff --git a/judge/bridge/judge_handler.py b/judge/bridge/judge_handler.py index 1ff1af1..6aefc5c 100644 --- a/judge/bridge/judge_handler.py +++ b/judge/bridge/judge_handler.py @@ -24,6 +24,7 @@ from judge.models import ( Submission, SubmissionTestCase, ) +from judge.bridge.utils import VanishedSubmission logger = logging.getLogger("judge.bridge") json_log = logging.getLogger("judge.json.bridge") @@ -310,6 +311,9 @@ class JudgeHandler(ZlibPacketHandler): def submit(self, id, problem, language, source): data = self.get_related_submission_data(id) + if not data: + self._update_internal_error_submission(id, "Submission vanished") + raise VanishedSubmission() self._working = id self._working_data = { "problem": problem, @@ -658,8 +662,11 @@ class JudgeHandler(ZlibPacketHandler): self._free_self(packet) id = packet["submission-id"] + self._update_internal_error_submission(id, packet["message"]) + + def _update_internal_error_submission(self, id, message): if Submission.objects.filter(id=id).update( - status="IE", result="IE", error=packet["message"] + status="IE", result="IE", error=message ): event.post( "sub_%s" % Submission.get_id_secret(id), {"type": "internal-error"} @@ -667,9 +674,9 @@ class JudgeHandler(ZlibPacketHandler): self._post_update_submission(id, "internal-error", done=True) json_log.info( self._make_json_log( - packet, + sub=id, action="internal-error", - message=packet["message"], + message=message, finish=True, result="IE", ) @@ -678,10 +685,10 @@ class JudgeHandler(ZlibPacketHandler): logger.warning("Unknown submission: %s", id) json_log.error( self._make_json_log( - packet, + sub=id, action="internal-error", info="unknown submission", - message=packet["message"], + message=message, finish=True, result="IE", ) diff --git a/judge/bridge/judge_list.py b/judge/bridge/judge_list.py index 0552de4..bf2b54a 100644 --- a/judge/bridge/judge_list.py +++ b/judge/bridge/judge_list.py @@ -3,6 +3,8 @@ from collections import namedtuple from operator import attrgetter from threading import RLock +from judge.bridge.utils import VanishedSubmission + try: from llist import dllist except ImportError: @@ -39,6 +41,8 @@ class JudgeList(object): ) try: judge.submit(id, problem, language, source) + except VanishedSubmission: + pass except Exception: logger.exception( "Failed to dispatch %d (%s, %s) to %s", diff --git a/judge/bridge/utils.py b/judge/bridge/utils.py new file mode 100644 index 0000000..dfb2ac9 --- /dev/null +++ b/judge/bridge/utils.py @@ -0,0 +1,2 @@ +class VanishedSubmission(Exception): + pass