The following "write file", "check hash" in intermediate cases ( only sometimes) fails in an Electron 8.2.1 application. It will display that it has calculated d41d8cd98f00b204e9800998ecf8427e which is the hash over an empty string. However when i look in the folder, the file exists. So my assumption is that somehow sometimes that fs.writeFile under higher load still is not ready writing or something the file returns an empty string instead of the contents. And note that in 99% of the cases the application runs correctly. Only in some cases (and we think very high load) this fails.
I read node - fs.writeFile creates a blank file which comes closer but it does not provide a reason or "why the hell" nor because of this you need to do that.
fs.writeFile(cPath, body, 'utf-8', (err) => {
if (err) {
errors.handleErrorLocal(err);
reject();
return;
}
log.info(cFile + ' C HASH is:' + hash + ' HASH calculated:' + md5File.sync(cPath))
if (hash && md5File.sync(cPath) !== hash.toLowerCase()) {
log.warn('C failed to download. Wrong Hash. ', cFile)
}
resolve();
});
The answer on node.js readfile woes from panu-logic seems to correspond with this experience (bottom answer) but also does not provide any reason why other than "magical" in his case however he tries to read while being written. "logically" this is not the case but the assumption is that this is for some unknown reason the case.
I am aware that i could rewrite to stream or await but that requiress me to change it , push it out, waiting for some time for bugs then retry. I would rather know before all of this what the reason is and just know for sure that the fix for this works rather than stretching this over weeks or months.