duckdb-node icon indicating copy to clipboard operation
duckdb-node copied to clipboard

Cannot open a READ_WRITE connection after a READ_ONLY connection even if it is closed

Open Rosslington opened this issue 2 years ago • 4 comments

I might be doing something wrong here, but I'm wanting to use both READ_ONLY connections and READ_WRITE connections and even though it works most of the time there are cases where a READ_ONLY connection is ran first and once that happens any subsequent READ_WRITE connections fail to be created.

This is using Promises and async/await so I'm specifically waiting for connections to close before opening new connections as I know you can only have one READ_WRITE connection at a time.

Here is a Gist for example: https://gist.github.com/Rosslington/9aecbb3eb51386cd684cc6e538bfcfb9

Rosslington avatar Dec 11 '23 12:12 Rosslington

I do not reproduce, using MacOS on either v0.9.2 or v0.10.0. Can you share more details of your setup?

Executing your reproduction like node reproduction.js I see behaviour as expected (so database opened with the various permissions as instructed).

carlopi avatar Feb 23 '24 18:02 carlopi

Ah that's annoying. If it helps, this is running on Windows 11 v23H2 - Nodejs v21.2.0 - Duckdb v0.9.2

Rosslington avatar Feb 26 '24 10:02 Rosslington

I'm running into the same issue. @ Windows 11 23H2 - Node.js v20.11.0 - DuckDB v1.0.0

My use case:

const tmpFilepath = './tmp/duckdb.db';

// Open a new db file with RW permissions so it would create the file
const db = new Database(tmpFilepath);

// Perform a query operation
await new Promise((resolve, reject) => {
  db.run(`SELECT current_catalog()`, (error) => {
    if (error) {
        console.log(error);
        reject(error);
    }
    resolve();
  });
});

// Request releasing Database resources
await await new Promise((resolve, reject) => {
  db.close((error) => {
    if (error) {
      console.log(error);
      reject(error);
    }
    resolve();
  });
)};

// Try to delete the file
await await new Promise((resolve, reject) => {
  fs.rm(tmpFilepath, { recursive: true, force: true }, (error) => {
    if (error) { // << "Error: EBUSY: resource busy or locked, unlink '<REMOVED>\tmp\duckdb.db'"
      console.log(error);
      reject(error);
    }
    resolve();
  });
)};

Note: When I remove the SELECT current_catalog() query call the file is not locked and can be deleted.

vellotis avatar Aug 01 '24 12:08 vellotis

i face the same problem like @vellotis .after close the db.the db file is still locked and can't remove!

superkidsXin avatar Aug 08 '24 15:08 superkidsXin