duckdb / duckdb/duckdb-node

after duck db close,the db file still locked

Open
#111 6 comments 0 reactions 0 assignees View on GitHub
under review
Dominant language
C++
Stars
91
Forks
36
PR merge metrics
No merged PRs in 30d

Description

### 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

```js
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 (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?

- [X] Yes, I have

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

- [X] Yes, I have

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.