Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Report]: Error: EBUSY: resource busy or locked after PDF conversion #101

Open
Sawalhah opened this issue Oct 19, 2020 · 4 comments
Open
Labels
P: High S: on hold The issue is on hold until further notice T: bug Functionality that does not work as intended/expected

Comments

@Sawalhah
Copy link

Environment
Carbone Version: [email protected]
Node Version: Node v12.18.0
Desktop OS: Windows 10 x64
Other: LibreOffice: 7.0.2

I've started a PDF generation test, the document generated but I get an error

    throw err;
    ^

Error: EBUSY: resource busy or locked, unlink 'C:\Users\{user}\AppData\Local\Temp\_office_c_1603106270380_5444_1\user\extensions\bundled\extensions.pmap'
    at Object.unlinkSync (fs.js:1129:3)
    at Object.rmDirRecursive (E:\carbone\node_modules\carbone\lib\helper.js:103:12)
    at Object.rmDirRecursive (E:\carbone\node_modules\carbone\lib\helper.js:107:14)
    at Object.rmDirRecursive (E:\carbone\node_modules\carbone\lib\helper.js:107:14)
    at Object.rmDirRecursive (E:\carbone\node_modules\carbone\lib\helper.js:107:14)
    at Object.exit (E:\carbone\node_modules\carbone\lib\converter.js:114:18)
    at process.<anonymous> (E:\carbone\node_modules\carbone\lib\converter.js:652:13)
    at process.emit (events.js:315:20)
    at process.exit (internal/process/per_thread.js:167:15)
    at E:\carbone\main.js:36:15 {
  errno: -4082,
  syscall: 'unlink',
  code: 'EBUSY',
  path: 'C:\\Users\\{USER}\\AppData\\Local\\Temp\\_office_c_1603106270380_5444_1\\user\\extensions\\bundled\\extensions.pmap'
}
@Sawalhah Sawalhah added the T: bug Functionality that does not work as intended/expected label Oct 19, 2020
@steevepay steevepay added P: High S: on hold The issue is on hold until further notice labels Oct 30, 2020
@steevepay
Copy link
Member

Hello @Sawalhah, thank you for reporting the issue, I also got an issue to generate a PDF on Windows.
Time to investigate.

@steevepay steevepay mentioned this issue Nov 3, 2020
21 tasks
@steevepay steevepay reopened this Sep 16, 2021
@NTTAKR
Copy link

NTTAKR commented Jan 27, 2022

Any news on this issue? Still happening with current versions available and the simplest pdf generation.

@NyanCetch
Copy link

Found a workaround on Windows to get around this problem. In short, the problem arises in the exit method in the converter.js file when time folders are deleted from the Temp folder. The LibreOffice process does not have time to release the files that must be deleted in time. Therefore, it was decided to comment on the code section that removes these time folders at the time the process is closing. Instead of this path, temporary folders are saved to a text file. In a separate script, we read these paths and delete everything that should have been deleted, after which we delete this file with the paths.

converter.js

var cleanupPaths = [];
for (var i in conversionFactory) {
  var _factory = conversionFactory[i];
  // if a factory is running
  if (_factory && (_factory.pythonThread !== null || _factory.officeThread !== null)) {
    clearTimeout(_factory.timeoutId);
    _factory.exitCallback = factoryExitFn;
    // kill Python thread first.
    if (_factory.pythonThread !== null) {
      _factory.pythonThread.kill('SIGKILL');
    }
    if (_factory.officeThread !== null) {
      _factory.officeThread.kill('SIGKILL');
      cleanupPaths = cleanupPaths.concat(_factory.userCachePath);
      // helper.rmDirRecursive(_factory.userCachePath);
    }
  }
}

fs.writeFileSync('user_cache.json', JSON.stringify(cleanupPaths));

cleanup_cache.js

var fs = require('fs');
var helper = require('./node_modules/carbone/lib/helper');


var jsonFile = 'user_cache.json';

try {
    // check if file exists
    if (fs.existsSync(jsonFile)) {
        console.log('Found cleanup file!');

        // read json
        var jsonData = fs.readFileSync(jsonFile);
        var cleanupPaths = JSON.parse(jsonData);

        console.log('Clean started...');

        // remove dirs
        for (var i in cleanupPaths) {
            helper.rmDirRecursive(cleanupPaths[i]);
        }
        console.log('Cache dirs cleared!');

        // delete cleanup file
        fs.unlinkSync(jsonFile);
        console.log('Cleanup file deleted!');

        console.log('Clean done!');
    } else {
        console.log('Cleanup file not found. Skip clean!');
    }
} catch(err) {
    console.log(err);
}

@xianguoGou
Copy link

I also encountered the same problem, have you solved it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P: High S: on hold The issue is on hold until further notice T: bug Functionality that does not work as intended/expected
Projects
None yet
Development

No branches or pull requests

5 participants