You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 13, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Jan 13, 2024. It is now read-only.
Error: EBUSY: resource busy or locked on native modules #1589
I experienced the same behavior when executing multiple instances of packed executable. It seems like native module is locked in "FILE LOCKED WITH ONLY READERS" mode and second instance tries to open it in write mode. Please see attached log.
I'm not sure but this could be related to PR1492 in 5.6.0. The .node files are always copied now to make sure that the temp folder contains all related files, see PR for details. But if there is an already running instance the native module files are already opened and therefore cannot be overwritten. Solution could be to perform always the copy action, just to make sure that the tmp folder is always properly populated, but to allow to fail. Then the second instance of the pkg app should just proceed with the already existing file.
For instance, copyFolderRecursiveSync in line 183 of prelude/bootstrap.js could be modified like this:
functioncopyFolderRecursiveSync(source,target){letfiles=[];// Check if folder needs to be created or integratedconsttargetFolder=path.join(target,path.basename(source));if(!fs.existsSync(targetFolder)){fs.mkdirSync(targetFolder);}// Copyif(fs.lstatSync(source).isDirectory()){files=fs.readdirSync(source);files.forEach((file)=>{constcurSource=path.join(source,file);if(fs.lstatSync(curSource).isDirectory()){copyFolderRecursiveSync(curSource,targetFolder);}else{try{fs.copyFileSync(curSource,path.join(targetFolder,path.basename(curSource)));}catch(err){// copyInChunks inside copyFileSync failed,// let us know, but proceed with next file.console.error(err)}}});}}
I'm not familiar with the code base, so please feel free to correct me or to point me to another solution. I can also provide a PR if this is suggested.
In general, the app start takes longer now since everything is always copied. Apps build with pkg 5.5.2 starts much faster the second time. Maybe it is a better idea in contrast to my suggestion above (try to copy but allow to fail if the file is already in use) to check before if the file already exists and if so to skip the copy.
This should guarantee that the tmp folder is always properly populated while it also speeds up the app start like in pkg 5.5.2 if all files are already there (best case).
PR is available now, I've tested this PR with my pkg-packaged app that uses .node files. Works fine again.
The PR has two effects:
.node files that must exist on the real filesystem instead of the virtual snapshot filesystem (because of process.dlopen) are only copied if they do not exist. If they already exist then it doesn't matter anymore whether they are currently opened by an running instance of the pkg-packaged app or not, because existing files are untouched now.
The start of the pkg app a second, third, etc. time is as fast as with pkg 5.5.2 again since (in best case) no copy action takes place.
But in case of missing .node files in the tmp folder the missing files are copied again, even if the folder structure is still existing. This makes PR1492 still relevant and important. Sometimes (at least on Windows) the folder structure inside the tmp folder was still there but the .node files were gone.
Please review, if everything is OK for you I'm looking forward to see pkg 5.6.1 ;-)
Activity
marcinadrem commentedon Apr 22, 2022
I experienced the same behavior when executing multiple instances of packed executable. It seems like native module is locked in "FILE LOCKED WITH ONLY READERS" mode and second instance tries to open it in write mode. Please see attached log.
Logfile.CSV
Please unpack attached file and run run_test.bat to reproduce
load_native_module_test.zip
renkei commentedon Apr 25, 2022
I'm not sure but this could be related to PR1492 in 5.6.0. The .node files are always copied now to make sure that the temp folder contains all related files, see PR for details. But if there is an already running instance the native module files are already opened and therefore cannot be overwritten. Solution could be to perform always the copy action, just to make sure that the tmp folder is always properly populated, but to allow to fail. Then the second instance of the pkg app should just proceed with the already existing file.
For instance, copyFolderRecursiveSync in line 183 of
prelude/bootstrap.jscould be modified like this:I'm not familiar with the code base, so please feel free to correct me or to point me to another solution. I can also provide a PR if this is suggested.
renkei commentedon Apr 26, 2022
In general, the app start takes longer now since everything is always copied. Apps build with pkg 5.5.2 starts much faster the second time. Maybe it is a better idea in contrast to my suggestion above (try to copy but allow to fail if the file is already in use) to check before if the file already exists and if so to skip the copy.
This should guarantee that the tmp folder is always properly populated while it also speeds up the app start like in pkg 5.5.2 if all files are already there (best case).
luckyyyyy commentedon Apr 28, 2022
same problem here, Multiple processes create files, thread unsafe
robertsLando commentedon Apr 29, 2022
Anyone that wants to create a PR to fix this? The part of code that creates the problem is identified so it's just a matter of doing some tests
mertushka commentedon Apr 29, 2022
@renkei Can you test the code you wrote on the local? If everything is good then you would make pr.
renkei commentedon Apr 29, 2022
I will try to create a PR over the weekend.
fix vercel#1589
renkei commentedon May 1, 2022
PR is available now, I've tested this PR with my pkg-packaged app that uses
.nodefiles. Works fine again.The PR has two effects:
.nodefiles that must exist on the real filesystem instead of the virtual snapshot filesystem (because of process.dlopen) are only copied if they do not exist. If they already exist then it doesn't matter anymore whether they are currently opened by an running instance of the pkg-packaged app or not, because existing files are untouched now.But in case of missing
.nodefiles in the tmp folder the missing files are copied again, even if the folder structure is still existing. This makes PR1492 still relevant and important. Sometimes (at least on Windows) the folder structure inside the tmp folder was still there but the.nodefiles were gone.Please review, if everything is OK for you I'm looking forward to see pkg 5.6.1 ;-)
fix vercel#1589
fix(bootstrap): prevent overriding existing node addon file (#1611)