[BUG] <The library seems to not be safe with multiple webworkers>

Open
#57 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
electron, javascript
Domain
tooling

Research direction

Start at the writeFileSync entry point and compare it with writeFile, as the report suggests both may be affected. Reproduce concurrent writes to the same file from multiple webworkers in Electron and trace the temporary-file, permission, write, and deletion sequence. Done means concurrent writes no longer fail with the reported ENOENT error while preserving atomic behavior.

Written by the indexing model from the issue text.

Description

Bug

What / Why

With reference with the following but https://github.com/sindresorhus/conf/issues/102, it appears that in a multiple webworker environment the library may have problems.
I'm working inside an electron app.

What is happening when multiple webworkers try to write the same file:

  • Webworker 1 -> create tmp file
  • Webworker 2 -> create same tmp file (apparently the file name depends on the pid, which is the same from all the webworkers, at least in an electron environment)
  • Webworker 1 -> set file permission, write the file and delete it
  • Webworker 2 -> set file permission, but cannot since the file does not exists anymore. And throw an exception.

I'm getting the following exception:

ENOENT: no such file or directory, chown '/Users/oltreseba/Library/Preferences/project-nodejs/config.json.1638900804'

When

This happen when i try to write the same file from multiple webworkers. It may not happen always since it's related with multithreading.

Where

writeFileSync function. But probably writeFile has the same problem?

How

Current Behavior

The function throw an exception when attempting to write a not-exiting file.

Steps to Reproduce

Start multiple workers that write to the same file.

Expected Behavior

The file access should be piped probably?

Dominant language
JavaScript
Stars
256
Forks
51
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from npm/write-file-atomic

All issues in npm/write-file-atomic

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.