m4heshd / better-sqlite3-multiple-ciphers

better-sqlite3 with multiple-cipher encryption support 🔒
MIT License
137 stars 27 forks source link

Bug: application crashes when creating database, using Electron #59

Closed NoxFly closed 10 months ago

NoxFly commented 11 months ago

Hello,

Tech : Node v18.13.0 npm v9.2.0 Electron v26.0 Javascript (not Typescript) Linux Ubuntu 23.04.

From my researches on StackOverflow and Github, the versions I mentionned above are not relevant. Minimal node version from my researches : 14 Minimal Electron version from my researches : 11 Javascript & Typescript. All OS.

In my case, I needed to electron-rebuild -f -w better-sqlite3-multiple-ciphers because of my node version before using this library.

const sqlite = require('better-sqlite3-multiple-ciphers');

const db = sqlite('data.db');

This code is sufficient to cause a crash. This occurs only when this is run through an Electron project.

Execute without Electron, all is working well.

The crash message :

/home/noxfly/codes/nodejs/electron/test/node_modules/electron/dist/electron exited with signal SIGSEGV

A lot of issues are opened in a lot of other library's repositories with the same behavior, always lambda library + Electron = SIGSEGV from Electron.

I don't know if it is to Electron's team to do something or the other library's team to find an alternative, and what us, end users, can do (because we would like to use both. Personnally I don't see other lib for database encryption and I don't know how to do myself, and of course keep electron for the main purpose of the application).

NoxFly commented 11 months ago

It seems that this issue is due to better-sqlite3 directly. Using another package (enmap) which also uses better-sqlite3, crashes when creating database, again with a SIGEGV.

willemdjong commented 11 months ago

Same here, https://github.com/m4heshd/better-sqlite3-multiple-ciphers/issues/57 after upgrading to electron v26.

m4heshd commented 11 months ago

There are third-party issues being tracked regarding this bug.

https://github.com/WiseLibs/better-sqlite3/pull/1042 https://github.com/prebuild/prebuild/issues/309

Will keep this issue open till those are addressed.

jepiqueau commented 11 months ago

I got the same issue with @capacitor-community/sqlite which use better-sqlite3-multiple-ciphers for the Electron part of the plugin capacitor-community/sqlite_issue#474. The plugin work fine with Electron 25.8.4 and better-sqlite3-multiple-ciphers 8.4.0 but when i upgrade Electron to 26.1.0 it failed:

called ipcMain.handle: CapacitorSQLite-open
/Volumes/Development_Lacie/Development/ionic7/angular-sqlite-app-starter/electron/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron exited with signal SIGSEGV
-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Process:               Electron [23496]
Path:                  /Volumes/VOLUME/*/Electron.app/Contents/MacOS/Electron
Identifier:            com.github.Electron
Version:               26.2.4 (26.2.4)
Code Type:             X86-64 (Native)
Parent Process:        node [23495]
Responsible:           Terminal [1462]
User ID:               501

Date/Time:             2023-10-01 11:50:01.7501 +0200
OS Version:            macOS 12.6.9 (21G726)
Report Version:        12
Bridge OS Version:     3.0 (14Y910)
Anonymous UUID:        F52BD279-4C53-B6B9-C38C-1439CFB5C8F0

Time Awake Since Boot: 19000 seconds

System Integrity Protection: enabled

Crashed Thread:        0  CrBrowserMain  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000014078
Exception Codes:       0x0000000000000001, 0x0000000000014078
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    Namespace SIGNAL, Code 11 Segmentation fault: 11
Terminating Process:   exc handler [23496]

VM Region Info: 0x14078 is not in any region.  Bytes before following region: 4516044680
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                      10d2ea000-10d2ec000    [    8K] r-x/r-x SM=COW  ...acOS/Electron

Thread 0 Crashed:: CrBrowserMain Dispatch queue: com.apple.main-thread
0   better_sqlite3.node                    0x11425bd6c Statement::JS_new(v8::FunctionCallbackInfo<v8::Value> const&) + 188
1   Electron Framework                     0x11fae5304 v8::internal::Accessors::MakeAccessor(v8::internal::Isolate*, v8::internal

my node version is v18.17.1

willemdjong commented 10 months ago

Any updates?

NoxFly commented 10 months ago

Any updates?

from this issue, Updating to Electron 27 solves the issue. The issue is caused by internal dependency of Electron, (prebuild), and there's a discussion that partially explain that here.

It's not totally resolving the real issue, but at least there's a workaround.

willemdjong commented 10 months ago

Upgrade to v27 solved it.

m4heshd commented 10 months ago

Closing this issue since this is as far as we're going to get to a fix until better-sqlite3 migrates to N-API.

jepiqueau commented 10 months ago

@m4heshd any idea on the plan date?

m4heshd commented 10 months ago

@jepiqueau As far as I know, there are no plans in place yet. It's ultimately up to @JoshuaWise to decide since it's gonna be a massive refactor.

jepiqueau commented 10 months ago

@m4heshd @JoshuaWise OK thanks keep me aware when the decision will happen