fix(run-multiple): avoid temp.mjs filename collision across forked processes#5644
Closed
kapil971390 wants to merge 1 commit into
Closed
fix(run-multiple): avoid temp.mjs filename collision across forked processes#5644kapil971390 wants to merge 1 commit into
kapil971390 wants to merge 1 commit into
Conversation
…ocesses
When run-multiple forks N concurrent processes, each process transpiles the
same .ts files (config, helpers, includes) to identically named *.temp.mjs
files. A process that finishes first deletes its temp file, causing other
processes that haven't imported it yet to fail with "Cannot find module
*.temp.mjs".
Fix: embed process.pid in the temp filename so every worker writes its own
isolated copy. Cleanup still works because allTempFiles is built from
transpiledFiles.values(), which already contains the pid-suffixed paths.
The .includes('.temp.mjs') substring check in step/base.js continues to
match the new *.{pid}.temp.mjs filenames.
Fixes codeceptjs#5642
Contributor
Author
Contributor
|
Indeed. That's great! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #5642
When
run-multiplelaunches N concurrent worker processes, each process independently transpiles the same TypeScript files (config, helpers, page objects, includes) to temporary.temp.mjsfiles. Since the temp filename is derived purely from the source path:all workers write to the same path (e.g.
CustomHelper.temp.mjs). When one worker finishes and deletes its temp file viacleanupTempFiles(), any other worker that hasn't yetimport()ed the file fails with:This is a classic TOCTOU race; the repro in #5642 shows it failing ~85% of the time with 12 workers.
Fix
Embed
process.pidin the temp filename so each worker writes its own isolated copy:No other changes needed:
cleanupTempFiles()iteratesallTempFileswhich is built fromtranspiledFiles.values()— already contains the pid-suffixed paths, so cleanup is correct.lib/step/base.jsuses.includes('.temp.mjs')(substring), which matches*.{pid}.temp.mjsunchanged.Test plan
run-multipleno longer races on the repro from 4.x: The test in the mode "run-multiple" sometimes fails: "Cannot find module *.temp.mjs" #5642 (run 40 iterations, all pass)runstill works (temp files created, imported, cleaned up normally)