sindresorhus/conf

The library seems to not be multithread safe

oltreseba opened this issue · 2 comments

I'm using conf inside in an electron application inside some webworkers.

The reason why i'm not using electron-store is that it does not work in webworkers.

conf seems to have problem in initialising the config file from different webworkers. The underlying problem seems to be related with the write-file-atomic package, function writeFileSync

What is it doing: (i assume for avoiding having corrupted files)

  • creating a tmp config file
  • writing in the file
  • renaming it

What can happen in a multithread environment:

  • 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)
  • 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 and exception.

The exception i'm getting is:

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

I would recommend opening an issue on write-file-atomic about this. It should support Webworkers.

Right. Done.