coreybutler / node-windows

Windows support for Node.JS scripts (daemons, eventlog, UAC, etc).
Other
2.83k stars 356 forks source link

Error while creating daemon folder: daemon already exists #359

Open kern3l-pan1c opened 1 year ago

kern3l-pan1c commented 1 year ago

Issue: On a fresh machine (where node-windows has never run before), if I initiate two or more installs (of different services) simultaneously, we see an intermittent issue where:

  1. For one or more installs, fs.exists (https://github.com/coreybutler/node-windows/blob/27779d9caafe9854fa5767574ac288d98447c0ff/lib/daemon.js#L540) does not find the daemon folder (because nod-windows has not been run yet and daemon folder is actually not there).
  2. Since fs.exists is async (also deprecated), all calls in step 1 will try to create the daemon folder.
  3. This leads to a collision where all the installs after the first one (whoever gets to create daemon folder) will fail with an error saying daemon folder already exists.

How To Reproduce: Give multiple install commands simultaneously.

Expected Behavior: daemon folder should be created without errors and services should get installed.

Desktop:

Probable Fix: We should be using the fs.existsSync function instead of fs.exists at https://github.com/coreybutler/node-windows/blob/27779d9caafe9854fa5767574ac288d98447c0ff/lib/daemon.js#L540 @coreybutler if you want, I can raise a PR with this fix

kern3l-pan1c commented 1 year ago

@coreybutler I have created https://github.com/coreybutler/node-windows/pull/360 with the fix