Skip to content

Commit 8bfe636

Browse files
committed
Stop services giving the same ID to all their sandboxes
This helps in case of task that require multiple sandboxes (like those of Communication type) to reduce mutual interferences.
1 parent 7b692dc commit 8bfe636

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

cms/grading/Sandbox.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,8 @@ class IsolateSandbox(SandboxBase):
757757
command number N.
758758
759759
"""
760+
next_id = 0
761+
760762
def __init__(self, file_cacher=None, temp_dir=None):
761763
"""Initialization.
762764
@@ -765,15 +767,19 @@ def __init__(self, file_cacher=None, temp_dir=None):
765767
"""
766768
SandboxBase.__init__(self, file_cacher)
767769

768-
# Get our shard number, to use as a unique identifier for the
769-
# sandbox on this machine. FIXME This is the only use of
770-
# FileCacher.service, and it's an improper use! Avoid it!
770+
# Isolate only accepts ids between 0 and 99. We assign the
771+
# range [(shard+1)*10, (shard+2)*10) to each Worker and keep
772+
# the range [0, 10) for other uses (command-line scripts like
773+
# cmsMake or direct console users of isolate). Inside each
774+
# range ids are assigned sequentially, with a wrap-around.
775+
# FIXME This is the only use of FileCacher.service, and it's an
776+
# improper use! Avoid it!
771777
if file_cacher is not None and file_cacher.service is not None:
772-
# We add 1 to avoid conflicting with console users of the
773-
# sandbox who use the default box id of 0.
774-
box_id = file_cacher.service.shard + 1
778+
box_id = ((file_cacher.service.shard + 1) * 10
779+
+ (IsolateSandbox.next_id % 10)) % 100
775780
else:
776-
box_id = 0
781+
box_id = IsolateSandbox.next_id % 10
782+
IsolateSandbox.next_id += 1
777783

778784
# We create a directory "tmp" inside the outer temporary directory,
779785
# because the sandbox will bind-mount the inner one. The sandbox also

0 commit comments

Comments
 (0)