diff options
author | 2022-11-18 13:36:56 -0500 | |
---|---|---|
committer | 2022-11-18 13:36:56 -0500 | |
commit | ff943403321f2b17b34cf832dcddfdcde85f2e35 (patch) | |
tree | 91d32d91e505249e42974833db9e63dc851751dd | |
parent | Reorder `mkdir` function (diff) |
Add PID to UUID generation
- Use current process PID in addition to UUID to avoid collisions with multiple snekbox instances (albeit unlikely)
-rw-r--r-- | snekbox/memfs.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/snekbox/memfs.py b/snekbox/memfs.py index 8d0841b..e5f85aa 100644 --- a/snekbox/memfs.py +++ b/snekbox/memfs.py @@ -2,6 +2,7 @@ from __future__ import annotations import logging +import os import subprocess from collections.abc import Generator from contextlib import contextmanager @@ -16,6 +17,8 @@ from snekbox.snekio import FileAttachment log = logging.getLogger(__name__) +PID = os.getpid() + NAMESPACE_DIR = Path("/memfs") NAMESPACE_DIR.mkdir(exist_ok=True) NAMESPACE_DIR.chmod(0o711) # Execute only access for other users @@ -82,8 +85,8 @@ class MemFS: # Generates a uuid tempdir with self.assignment_lock: for _ in range(10): - name = str(uuid4()) - if name not in self.assigned_names: + # Combine PID to avoid collisions with multiple snekbox processes + if name := f"{PID}-{uuid4()}" not in self.assigned_names: self.path = mount_tmpfs(name, self.instance_size) self.assigned_names.add(name) break |