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

after duck db close,the db file still locked #111

Open
2 tasks done
ftyszyx opened this issue Aug 9, 2024 · 5 comments
Open
2 tasks done

after duck db close,the db file still locked #111

ftyszyx opened this issue Aug 9, 2024 · 5 comments

Comments

@ftyszyx
Copy link

ftyszyx commented Aug 9, 2024

What happens?

I am use duckdb in node enviroment.but I found a very serious bug.
after I close duck db by api,I stilll can't remove db file,because the db file is locked.
"Error: EBUSY: resource busy or locked, unlink"

I write a demo project to reproduce the problem : https://github.com/ftyszyx/test_duckdb

can anyone help me?

To Reproduce

import duckdb from "duckdb";
import fs from "fs";

let db = null;
// Open a new db file with RW permissions so it would create the file
async function openDb() {
  if (db) {
    console.log("db already opened");
    return;
  }
  return new Promise((resolve, reject) => {
    db = new duckdb.Database("duck.db", { access_mode: "READ_WRITE" }, (err) => {
      if (err) {
        console.log("open db error", err);
        db = null;
        reject(err);
        return;
      } else {
        console.log("db opened successfully");
        resolve();
      }
    });
  });
}

async function closeDb() {
  if (db === null) {
    console.log("db already closed");
    return;
  }
  return new Promise((resolve, reject) => {
    db.close((err) => {
      if (err) {
        console.log("close db error", err);
        reject(err);
        return;
      } else {
        console.log("db closed successfully");
        resolve();
      }
    });
  });
}

async function runsql(text) {
  return new Promise((resolve, reject) => {
    db.run(text, (error) => {
      if (error) {
        console.log("run sql err", error);
        reject(error);
      } else {
        console.log("runsql ok", text);
        resolve();
      }
    });
  });
}

await openDb();
await runsql("select 42 as fortytwo");
await closeDb();
fs.unlinkSync("duck.db");
console.log("del ok");

output err

db opened successfully
runsql ok select 42 as fortytwo
db closed successfully
node:fs:1877
  binding.unlink(path);
          ^

Error: EBUSY: resource busy or locked, unlink 'D:\mywork\learn_all\node\test_duckdb\duck.db'
    at Object.unlinkSync (node:fs:1877:11)
    at <anonymous> (D:\mywork\learn_all\node\test_duckdb\index.ts:62:4)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  errno: -4082,
  code: 'EBUSY',
  syscall: 'unlink',
  path: 'D:\\mywork\\learn_all\\node\\test_duckdb\\duck.db'
}

Node.js v20.14.0

OS:

windows

DuckDB Version:

1.0

DuckDB Client:

node.js

Full Name:

yuxin.zhang

Affiliation:

personal

What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have not tested with any build

Did you include all relevant data sets for reproducing the issue?

No - Other reason (please specify in the issue body)

Did you include all code required to reproduce the issue?

  • Yes, I have

Did you include all relevant configuration (e.g., CPU architecture, Python version, Linux distribution) to reproduce the issue?

  • Yes, I have
@Tishj
Copy link

Tishj commented Aug 9, 2024

Since this is Windows, my first thought is that this isn't something we have control over, Windows file system locks are much less responsive than Linux/Mac

But perhaps we're not properly closing the file handles and this is a real issue, so take this with a grain of salt

@ftyszyx
Copy link
Author

ftyszyx commented Aug 9, 2024

thank you for your reply @Tishj
I suspect the problem is the file handles not be released.
because if I delete the query line, do't do a sql query,the file will be del success!

await openDb();
await runsql("select 42 as fortytwo");
await closeDb();
fs.unlinkSync("duck.db");

@Mytherin Mytherin transferred this issue from duckdb/duckdb Aug 9, 2024
@franksmithinnovasea
Copy link

To confirm that this is still an issue, I just tried the demo after updating to 1.1.0, and it still produce the same error.

Is there an ETA on when this will be fixed? I'm willing to help with testing.

@Draiken
Copy link

Draiken commented Nov 20, 2024

I am hitting this issue also. Would love some update on it.

@ftyszyx
Copy link
Author

ftyszyx commented Nov 24, 2024

there is no offical fix,so i use sqlite to instead

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

No branches or pull requests

5 participants