duckdb / duckdb-node

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

after duck db close,the db file still locked

ftyszyx opened this issue · comments

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

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

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");

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.