-
Notifications
You must be signed in to change notification settings - Fork 14
Description
Issue Summary
When using @vscode/sqlite3@5.1.8-vscode on macOS in an Electron-based app, the application crashes during process shutdown if there are pending async sqlite3 operations. The crash happens in node_sqlite3::Statement::Work_AfterRun while libuv is draining the remaining work items during Node shutdown.
In Node’s shutdown phase (node::Stop), running JS callbacks is no longer allowed, but @vscode/sqlite3 still schedules async callbacks that try to call back into JS. With the 5.1.8 build configuration change (enabling NAPI_CPP_EXCEPTIONS / node_addon_api_except), when TRY_CATCH_CALL runs and napi_call_function returns napi_cannot_run_js, the NAPI_RETURN_OR_THROW_IF_FAILED macro throws a C++ exception instead of just raising a JS exception and returning, which aborts the process and crashes the app.
In 5.1.7, the addon was built with the configuration that reports errors by throwing a JS exception and returning, which avoids crashing the whole process in this shutdown scenario. Since 5.1.8 only changed the build configuration (not the sqlite3 C++ logic) and this new configuration does not fit @vscode/sqlite3’s usage pattern (many async callbacks that may run late in shutdown), this looks like a regression specific to @vscode/sqlite3. We would like to request reverting the 5.1.8 build configuration change for @vscode/sqlite3, or otherwise restoring the previous behavior where TRY_CATCH_CALL does not cause process‑terminating C++ exceptions in this case.
Steps to Reproduce
- On macOS, create a minimal Electron-based app (or Node app) that depends on "@vscode/sqlite3": "5.1.8-vscode".
- Use the following script to open an in‑memory database and continuously run async operations:
const sqlite3 = require('@vscode/sqlite3').verbose();
const db = new sqlite3.Database(':memory:');
db.serialize(() => {
db.run('CREATE TABLE lorem (info TEXT)');
let i = 11;
setInterval(() => {
const stmt = db.prepare('INSERT INTO lorem VALUES (?)');
i++;
stmt.run('Ipsum ' + i);
stmt.finalize();
db.each('SELECT * FROM lorem');
db.each('SELECT rowid AS id, info FROM lorem', (err, row) => {
// optional: inspect err / row
});
});
});
- Run the app, then quit the Electron app (e.g. Cmd+Q on macOS) while the interval is still running.
- Observe that the process crashes on exit with a stack trace ending in node_sqlite3::Statement::Work_AfterRun.
- Change the dependency to "@vscode/sqlite3": "5.1.7-vscode", rebuild, and repeat the steps; the crash no longer reproduces, indicating a regression introduced in 5.1.8.
Version
5.1.8
Node.js Version
22.16.0
How did you install the library?
Electron