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

EBUSY: resource busy or locked when stop server in tests #4

Open
StarpTech opened this issue Aug 10, 2017 · 3 comments
Open

EBUSY: resource busy or locked when stop server in tests #4

StarpTech opened this issue Aug 10, 2017 · 3 comments

Comments

@StarpTech
Copy link

EBUSY: resource busy or locked, unlink 'C:\Users\nk.dusdeu468\Documents\Repositorys\example\news\node_modules\mongo-in-memory\.data-iosi15q\mongod.lock'
      at Object.fs.unlinkSync (fs.js:1066:18)
      at rimrafSync (C:\Users\nk.dusdeu468\Documents\Repositorys\example\news\node_modules\rimraf\rimraf.js:305:17)
      at C:\Users\nk.dusdeu468\Documents\Repositorys\example\news\node_modules\rimraf\rimraf.js:341:5
      at Array.forEach (native)
      at rmkidsSync (C:\Users\nk.dusdeu468\Documents\Repositorys\example\news\node_modules\rimraf\rimraf.js:340:26)
@StarpTech StarpTech reopened this Aug 10, 2017
@StarpTech
Copy link
Author

StarpTech commented Aug 10, 2017

I run into the issue when I run multiple tests in serie. The data directories won't be deleted.

@smeijer
Copy link

smeijer commented Nov 1, 2017

Having this one also; it's a big problem when using it with Wallaby.js. It created 1500 .data directories within a day.

@smeijer
Copy link

smeijer commented Nov 1, 2017

Not really a solution; but I'm using a custom stop method to cleanup sibling directories that's been left earlier. This to reduce the noise a bit.

const getDataDirs = root => fs.readdirSync(root)
  .filter(f => fs.statSync(path.join(root, f)).isDirectory())
  .filter(d => /.data-[a-z0-9]{7}/.test(d))
  .map(d => path.join(root, d));

const tryDelete = dir => {
  try { rimraf.sync(dir) }
  catch (e) { }
};

async function stopMongo(server) {
  try {
    await server.stop();
  }
  catch (ex) {
    if (ex.code !== 'EBUSY' || ex.syscall !== 'unlink') {
      throw ex;
    }
  }
  finally {
    const root = server.databasePath.substr(0, server.databasePath.length - 13);
    getDataDirs(root).forEach(tryDelete);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants