Skip to content

Commit

Permalink
Ignore wrong contest submissions in ProxyService (cms-dev#1142)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
edomora97 authored and stefano-maggiolo committed Dec 21, 2021
1 parent 0c102eb commit 3f22b7e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions cms/service/ProxyService.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# Copyright © 2015 Luca Versari <[email protected]>
# Copyright © 2015 William Di Luigi <[email protected]>
# Copyright © 2016 Amir Keivan Mohtashami <[email protected]>
# Copyright © 2019 Edoardo Morassutto <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 3f22b7e

Please sign in to comment.