I have several independent scripts reading and writing from the same text files. I'm trying to lock the text files while a module is reading/writing from them. At the moment I am using the lockfile package but it does not seem to be working. e.g.
//lock file before reading
lockFile.lockSync("./Config/presetString.txt.lock",10000,100,10000,1000,100)
//read file
var preset = fs.readFileSync("./Config/presetString.txt", 'utf8');
//unlock file
lockFile.unlockSync("./Config/presetString.txt.lock",10000,100,10000,1000,100)
However, when lots of modules are running, it sometimes throws an error which brings everything to a halt. The error states that a .lock file already exists. This seems counterintuitive - if a .lock file already exists then the modules should wait until it doesn't exist.With the options above, the modules should retry accessing the lock 1000 times but this does not seem to be working.
Any ideas on how to prevent this?
Here is an example error that is thrown:
Error: EEXIST: file already exists, open './Config/presetString.txt.lock'