Skip to content

Commit 2dc9774

Browse files
committed
Use a specific lock file to avoid temp directory contention
Previously in debug mode we could try to avoid temp file contension by taking and holding the cache lock for the duration of the process. This change uses a specific lock file within the temp directory which avoid needing a writable cache directory. Its also more logical. Partial fix for #13369
1 parent 96ffe11 commit 2dc9774

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

emcc.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,14 +1927,6 @@ def get_full_import_name(name):
19271927
# exit block 'parse arguments and setup'
19281928
log_time('parse arguments and setup')
19291929

1930-
if DEBUG:
1931-
# we are about to start using temp dirs. serialize access to the temp dir
1932-
# when using EMCC_DEBUG, since we don't want multiple processes would to
1933-
# use it at once, they might collide if they happen to use the same
1934-
# tempfile names
1935-
shared.Cache.acquire_cache_lock()
1936-
atexit.register(shared.Cache.release_cache_lock)
1937-
19381930
if options.post_link:
19391931
process_libraries(libs, lib_dirs, temp_files)
19401932
if len(input_files) != 1:

tools/shared.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from . import cache, tempfiles, colored_logger
3030
from . import diagnostics
3131
from . import config
32+
from . import filelock
3233

3334

3435
DEBUG = int(os.environ.get('EMCC_DEBUG', '0'))
@@ -396,6 +397,16 @@ def __init__(self):
396397
except Exception as e:
397398
exit_with_error(str(e) + 'Could not create canonical temp dir. Check definition of TEMP_DIR in ' + config.config_file_location())
398399

400+
# Since the cannonical temp directory is, by definition, that same
401+
# between all processes that run in DEBUG mode we need to use a multi
402+
# process lock to prevent more than on process from writing to it.
403+
# This is because emcc assumes that it can use non-unique names inside
404+
# the temp directory.
405+
filelock_name = os.path.join(self.EMSCRIPTEN_TEMP_DIR, 'emscripten.lock')
406+
lock = filelock.FileLock(filelock_name)
407+
lock.acquire()
408+
atexit.register(lock.release)
409+
399410
def get_temp_files(self):
400411
return tempfiles.TempFiles(
401412
tmp=self.TEMP_DIR if not DEBUG else get_emscripten_temp_dir(),

0 commit comments

Comments
 (0)