When using the cached.Database function, and when providing a callback for error detection, multiple failed attempts to open the same database file will only call the first callback.
Attempting to open the database multiple times with listeners works as expected.
This problem manifests in the promise-based sqlite wrapper package, where attempting to open the same cached database multiple times will suspend subsequent promises indefinitely.
Steps to Reproduce
Run the following snippet:
import sqlite3 from "sqlite3"
function openDbWithCallback(n) {
sqlite3.cached.Database(
'does_not_exist_cb.db',
sqlite3.OPEN_READONLY,
(err) => {
if (err) {
console.log(open with callback #${n} failed: ${err});
}
});
}
openDbWithCallback(1);
openDbWithCallback(2);
function openDbWithListener(n) {
const db = sqlite3.cached.Database('does_not_exist_listener.db', sqlite3.OPEN_READONLY)
db.addListener('error', (err) => { console.log(open with listener #${n} failed: ${err}) })
}
openDbWithListener(1);
openDbWithListener(2);
2. Observe that "open with callback" is only logged once, while "open with listener" is logged twice (as expected).
### Version
5.1.7
### Node.js Version
22.9.0
### How did you install the library?
npm install with package.json on Windows 10 x64
Issue Summary
When using the
cached.Database
function, and when providing a callback for error detection, multiple failed attempts to open the same database file will only call the first callback.Attempting to open the database multiple times with listeners works as expected.
This problem manifests in the promise-based
sqlite
wrapper package, where attempting to open the same cached database multiple times will suspend subsequent promises indefinitely.Steps to Reproduce
function openDbWithCallback(n) { sqlite3.cached.Database( 'does_not_exist_cb.db', sqlite3.OPEN_READONLY, (err) => { if (err) { console.log(
open with callback #${n} failed: ${err}
); } }); }openDbWithCallback(1); openDbWithCallback(2);
function openDbWithListener(n) { const db = sqlite3.cached.Database('does_not_exist_listener.db', sqlite3.OPEN_READONLY) db.addListener('error', (err) => { console.log(
open with listener #${n} failed: ${err}
) }) }openDbWithListener(1); openDbWithListener(2);