From 3f22b7eacadc16eaa71868da7f1d9b5acbab3c88 Mon Sep 17 00:00:00 2001 From: Edoardo Morassutto Date: Fri, 17 Dec 2021 17:51:19 +0100 Subject: [PATCH] Ignore wrong contest submissions in ProxyService (#1142) * Ignore wrong contest submissions in ProxyService When you are running cms with more than a contest (ie multicontest) ProxyService can be notified by ScoringService of new submissions of any contest, ignoring the `-c X` flag of PS. This will lead to `Inconsistent Data` errors in RWS due to submissions of the wrong contest (bad user, bad task, ...). This is especially bad because the wrong submission can be sent with other valid submissions, and RWS drop them all. The proposed fix just ignores those submissions from ProxyService since ScoringService has no way to know which contest PS is bound to. * Move the contest_id checks in submission_scored/tokened * Move PS contest checks before submission validation Filter out the submissions from the wrong contest before rejecting them if they are hidden/unofficial. Add also some debug logging when it happens. This also adds the check in dataset_updated() since AWS may trigger the same kind of wrong RWS notifications. * Fix line lengths and message format --- cms/service/ProxyService.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/cms/service/ProxyService.py b/cms/service/ProxyService.py index 0d1b56ec3c..68b30271ab 100644 --- a/cms/service/ProxyService.py +++ b/cms/service/ProxyService.py @@ -9,6 +9,7 @@ # Copyright © 2015 Luca Versari # Copyright © 2015 William Di Luigi # Copyright © 2016 Amir Keivan Mohtashami +# Copyright © 2019 Edoardo Morassutto # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -476,6 +477,15 @@ def submission_scored(self, submission_id): "unexistent submission id %s.", submission_id) raise KeyError("Submission not found.") + # ScoringService sent us a submission of another contest, they + # do not know about our contest_id in multicontest setup. + if submission.task.contest_id != self.contest_id: + logger.debug("Ignoring submission %d of contest %d " + "(this ProxyService considers contest %d only).", + submission.id, submission.task.contest_id, + self.contest_id) + return + if submission.participation.hidden: logger.info("[submission_scored] Score for submission %d " "not sent because the participation is hidden.", @@ -511,6 +521,15 @@ def submission_tokened(self, submission_id): "unexistent submission id %s.", submission_id) raise KeyError("Submission not found.") + # ScoringService sent us a submission of another contest, they + # do not know about our contest_id in multicontest setup. + if submission.task.contest_id != self.contest_id: + logger.debug("Ignoring submission %d of contest %d " + "(this ProxyService considers contest %d only).", + submission.id, submission.task.contest_id, + self.contest_id) + return + if submission.participation.hidden: logger.info("[submission_tokened] Token for submission %d " "not sent because participation is hidden.", @@ -545,6 +564,15 @@ def dataset_updated(self, task_id): task = Task.get_from_id(task_id, session) dataset = task.active_dataset + # This ProxyService may focus on a different contest, and it should + # ignore this update. + if task.contest_id != self.contest_id: + logger.debug("Ignoring dataset change for task %d of contest " + "%d (this ProxyService considers contest %d " + "only).", task_id, task.contest.id, + self.contest_id) + return + logger.info("Dataset update for task %d (dataset now is %d).", task.id, dataset.id)