WiseLibs / better-sqlite3

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

Getting an Electron crash, not sure how to further debug - help needed! #988

Open rathboma opened 1 year ago

rathboma commented 1 year ago

Hi folks,

I'm getting a full-app crash in my Electron app (Beekeeper Studio). It seems to be coming from better-sqlite3, but I don't get a printed stacktrace at all. I only get crash details when using crashpad/breakpad.

I don't really know how to figure out where better-sqlite3 is crashing, but it seems to be the cause of the crash?

image

This only happens 1/10 of the time.

Versions:

mceachen commented 1 year ago

This isn't going to be the answer you're hoping for, but I found electron to be unstable when running native libraries from the main process. Current versions seem to be worse: I've had to pin to 21.4 as that seems to be the most recent version that works-ish.

For PhotoStructure, I have the main electron process spawn and monitor child processes (using ELECTRON_RUN_AS_NODE) to work around this. The spawned processes seem to be much happier to run native libraries.

See https://photostructure.com/server/photostructure-for-servers/#service-architecture for more details.

rathboma commented 1 year ago

@mceachen Hey, thanks for the response. Yeah I've noticed the same thing, and have similar plans, but haven't had the time to re-architect the application yet. It's quite a large change. :-/.

cbartondock commented 1 year ago

I am also seeing a crash in electron crash in Electron 24.1.2. Happens relatively randomly when a database is re-opened. Yes I am closing them.

rathboma commented 1 year ago

I downgraded to Electron 18 and that seems stable. Don't feel too bad about that as many big commercial apps are on 18 or earlier (eg vscode)

indutny-signal commented 1 year ago

FWIW, you might need to use patch like this to make it work: https://github.com/signalapp/better-sqlite3/commit/1bf85ef39eb587fae61d7c011603489a6eaa8e3e . It isn't pretty, but the underlying issue is that V8 used by Chromium/Electron treats the first aligned pointer slot as holding a reference to their C++ heap that can be GCed. Thus if it finds something unexpected there - it might crash.

rathboma commented 8 months ago

@indutny-signal I'm coming back to this issue thinking about how I upgrade my app to a new version of Electron.

Given that this is the version of V8 used by Electron -- is this problem present in all process types run by an electron app? Render, Main, and Utility?

I really know nothing about C++. Would this problem also be present in other native libraries (for me - Oracle's native libraries)

Thanks for any extra advice here.

indutny-signal commented 8 months ago

@rathboma I think the problem is only present in renderer process. If you use better-sqlite3 in main, it should be good to go without a patch.