-
Notifications
You must be signed in to change notification settings - Fork 293
fs.writeFileSync intermittently does not create file on disk when called in parallel #1002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
can you share you code? fs.XSync won't actually run in parallel, one call should block another. Any sync call will block. |
There isn't a whole lot of code I can share but I start the NodeJS script using the
where nBinary is Then in the NodeJS script at
where fileSystem contains the All of this code is running multiple times in parallel on the same Docker container If what you're saying about fs.writeFileSync methods blocking each other is occurring then wouldn't the writes still eventually happen once each call has gotten its turn? I'm currently trying to flush the buffer cache using |
how many Node.js processes are running? Any fs.xSync call will block in a given Node.js process, but if there is more than one process, then the fs calls will run independently / in parallel. |
by the way it's probably not |
can you dump the actual string that |
There's always more than one Node.js process running. In my testing it usually ranges from 3-7 processes. Each Node.js process will call fs.writeFileSync 1 to X times. The command is |
Yeah you are using 'n' not nvm to manage node versions - the report.js file
probably has a shebang/hashbang that makes it use the node executable.
Your problem is likely cause because more than one node.js processes is
writing to the same file at the same time.
Without more info, one thing I can suggest is using uuids for unique
filenames.
…On Nov 29, 2017 5:13 PM, "Wise" ***@***.***> wrote:
@ORESoftware <https://github.com/oresoftware>
There's always more than one Node.js process running. In my testing it
usually ranges from 3-7 processes. Each Node.js process will call
fs.writeFileSync 1 to X times.
The command is n use 8.8.1 /home/ubuntu/report.js
https://dswb.soasta.com:8443/notebooks/prebuilt%20notebooks/0.%20Getting%
20Started.ipynb
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1002 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AKn56HYJRPJWPy0HK91TTxkrWfJ6rRc4ks5s7gEygaJpZM4QviCR>
.
|
Actually each process initially starts in the same directory but |
Can you verify that it's actually changing directories properly? what exactly is the issue where the files are "overwriting" each other, if they are actually writing to different directories? |
I printed out the current working directory using a utility function and every process was operating within its own unique path. The overwriting issue revolves around the use of |
@cratter49 - is this still outstanding? |
closing due to inactivity |
I'm also noticing this behavior in unit tests. However, it seems to be a timing issue. The file is created, but This is weird behavior. |
I'm currently running a custom Jupyter notebook server within a Docker container. In this server there is code that executes a NodeJS script one or more times which launches an instance of headless chrome, extracts some information from the DOM of a page that instance of headless chrome points to, and then writes that information to a file in a temporary directory using
fs.writeFileSync
from the fs module. When this script is executed multiple times in parallel sometimes thefs.writeFileSync
does not seem to actually write the file to disk even though there are no errors thrown from the script. For example, when the script is executed six times in parallel on my Docker system one NodeJS process out of the six I launched will fail to write the file to disk. Additionally, I know that the file is written to a unique path with each execution of the script and using the asynchronous version ofwriteFile
does not work.Also, it's important to note that the file does not exist before this call is made.
Any ideas why the file write my not occur?
The text was updated successfully, but these errors were encountered: