hummusRecipe icon indicating copy to clipboard operation
hummusRecipe copied to clipboard

Appending document can cause files to be locked even after `.endDoc()`

Open WolfieZero opened this issue 5 years ago • 5 comments

To give a quick scenario; I'm splitting a document to two separate documents but using .split() and then .appendPage.

First...

const jobOutputDir = fs.mkdtempSync(jobDir + '/')
orignalDoc
    .split(jobOutputDir, prefix)
    .endPDF()

Then, after a few additional lines, we run this command...

const doc = new HummusRecipe('new', output)
files.forEach(file => doc.appendPage(file))
doc.endPDF()

Will create a file with no issues. But after that, running rimfaf on the directory where the files where location (either jobDir, or jobOutputDir) will give the following error

{ Error: EBUSY: resource busy or locked, unlink 'C:\Users\me\AppData\Local\Temp\myApp\8get8v2dmbaoovsv7u1ysdbo\Split\job\P6ZfdC\split-1.pdf'
    at Object.fs.unlinkSync (fs.js:1079:18)
    at rimrafSync (C:\Company\Code\myApp.foo\node_modules\rimraf\rimraf.js:306:17)
    at C:\Company\Code\myApp.foo\node_modules\rimraf\rimraf.js:342:5
    at Array.forEach (<anonymous>)
    at rmkidsSync (C:\Company\Code\myApp.foo\node_modules\rimraf\rimraf.js:341:26)
    at rmdirSync (C:\Company\Code\myApp.foo\node_modules\rimraf\rimraf.js:334:7)
    at rimrafSync (C:\Company\Code\myApp.foo\node_modules\rimraf\rimraf.js:304:9)
    at C:\Company\Code\myApp.foo\node_modules\rimraf\rimraf.js:342:5
    at Array.forEach (<anonymous>)
    at rmkidsSync (C:\Company\Code\myApp.foo\node_modules\rimraf\rimraf.js:341:26)
  errno: -4082,
  code: 'EBUSY',
  syscall: 'unlink',
  path: 'C:\\Users\\me\\AppData\\Local\\Temp\\myApp\\8get8v2dmbaoovsv7u1ysdbo\\Split\\job\\P6ZfdC\\split-1.pdf' }

I'm developing on both Windows 10 and macOS 14 and the problem happens 90-95% of the time on Windows 10. It's not consistent and calling functions as callbacks doesn't help either.

WolfieZero avatar Mar 26 '19 11:03 WolfieZero

Hello. I had the same issue today, but then I've found out the I could delete it manually. I set a timeout for 1 second before clean up files and it seems to work fine.

Rosga avatar Apr 09 '19 11:04 Rosga

I think I tried the timeout work-round but to no avail. Personally, it doesn't seem reliable to use a timeout if something is causing a lockout (rimraf does a timeout/retry when deleting I think).

WolfieZero avatar Apr 09 '19 11:04 WolfieZero

I have the same issue did you find a solution @WolfieZero

Ajmal-Jalal avatar Jul 23 '19 20:07 Ajmal-Jalal

I think the best thing I did was wrap the rimraf method with a try/catch and if it catches an error it will carry on and do the process next time around.

try {
	rimraf.sync(jobDir)
} catch(error) {
	console.error(error)
}

Of course, there's still the issue but I just ignore the problem for the time being ;)

WolfieZero avatar Jul 24 '19 09:07 WolfieZero

I'm facing the same issue. I can't remove a document I have just appened to another.

posti85 avatar Sep 22 '19 18:09 posti85