WiseLibs / better-sqlite3

The fastest and simplest library for SQLite3 in Node.js.
MIT License
5.46k stars 396 forks source link

Crashing when running v8.5.2 on Electron 26.1.0 on first function call to db #1053

Closed neoxpert closed 1 year ago

neoxpert commented 1 year ago

After updating a project to Electron 26.1.0 and better-sqlite3 to 8.5.2, the app immediatly crashed whenever the first function is called on a Database instance. The app was running on Windows 10 x64. The error reported is '[5204:0825/183808.198:ERROR:crashpad_client_win.cc(844)] not connected'.

A minimal example consiting of package.json and index.js looks like:

package.json

{
  "name": "minimal",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "electron .",
    "postinstall": "electron-builder install-app-deps"
  },
  "dependencies": {
    "better-sqlite3": "8.5.2",
    "electron": "26.1.0",
    "electron-builder": "24.6.3"
  }
}

index.js

const { app } = require("electron");

function onReady() {
    const Database = require('better-sqlite3');
    const db = new Database(':memory:', { timeout: 15000 });

    db.pragma('journal_mode = WAL;');
}

app.on('ready', onReady);

After installing and starting with npm run start the example app instantly crashes. Also happens with Electron 26.0.0. The issue disappears when reverting to Electron 25.7.0.

mceachen commented 1 year ago

Thanks for reporting. On Ubuntu 22.04.3 LTS, both PRAGMA and close() cause the SIGSEGV.

package.json:

{
  "name": "minimal",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "electron .",
    "postinstall": "electron-builder install-app-deps"
  },
  "dependencies": {
    "better-sqlite3": "8.5.2",
    "electron": "26.1.0",
    "electron-builder": "24.6.3",
    "segfault-handler": "1.3.0"
  },
  "overrides": {
    "node-gyp": "9.4.0"
  }
}

index.js:

const { app } = require("electron");

require('segfault-handler').registerHandler("crash.log")

function onReady() {
  console.log("pre require")
  const Database = require('better-sqlite3');
  console.log("post require")
  const db = new Database('/tmp/test.db', { timeout: 3000 });
  console.log("post new")
  db.pragma('journal_mode = WAL;');
  console.log("post pragma")
  db.close()
  console.log("post close")
  app.exit()
}

app.on('ready', onReady);```

```sh
$ npm start .

> minimal@1.0.0 start
> electron . .

pre require
post require
post new
PID 137441 received SIGSEGV for address: 0xb130
/tmp/test/node_modules/segfault-handler/build/Release/segfault-handler.node(+0x3775)[0x7f39ff96b775]
/lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7f3a01642520]
/tmp/test/node_modules/better-sqlite3/build/Release/better_sqlite3.node(_ZN9Statement6JS_newERKN2v820FunctionCallbackInfoINS0_5ValueEEE+0x4f9)[0x7f3971850f99]
/tmp/test/node_modules/electron/dist/electron .(+0x3674fce)[0x55a7b27c0fce]
/tmp/test/node_modules/electron/dist/electron exited with signal SIGSEGV

I can confirm that Electron 25 also avoids the SIGSEGV, and that opening either :memory: or normal files both result in the SIGSEGV.

mceachen commented 1 year ago

This is a duplicate of #1044 (but is a nice small repro, thanks!)