better-sqlite3: Crash when using prebuilt v8.5.2 with Electron 26.1.0

Error message before crash is

[20860:0821/201632.615257:ERROR:child_thread_impl.cc(235)] Invalid PlatformChannel receive right

Code is

      let database: Sqlite3Database.Database;
      try {
        database = new Sqlite3Database(':memory:', { verbose: logger.debug, nativeBinding: SQLITE_BINARY_PATH });
      } catch (error) {
        logger.error(`error when loading sqlite3 for workspace ${workspaceID}, skip because of error to prevent crash: ${(error as Error).message}`);
        return;
      }

It was working in 8.4.0 + “electron”: “25.2.0”,

Not working with 8.5.1 + “electron”: “26.0.0”, or 8.4.0 + + “electron”: “26.0.0”,

So it is electron’s falut.

About this issue

  • Original URL
  • State: open
  • Created 10 months ago
  • Reactions: 1
  • Comments: 19 (9 by maintainers)

Commits related to this issue

Most upvoted comments

If it’s relevant for anyone, the above commands I made an arch adjustment and it seems to work. I have to build mainly for x64 and was yelling at me about arm.

npx node-gyp rebuild --debug --build-from-source --runtime=electron --target=26.1.0 --dist-url=https://electronjs.org/headers --arch=x64  

Thanks, this worked for me. However, I’m still having issues with running it inside a Utility Process. The process just crashes right away with no log output that I can see. The main process which launches the utility process works fine.

Electron 27.0.0 seems to have resolved this issue for me.

Using @neoxpert 's repo, manually rebuilding fixes the issue:

npm install
cd node_modules/better-sqlite3
npx node-gyp rebuild --debug --build-from-source --runtime=electron --target=26.1.0 --dist-url=https://electronjs.org/headers
cd ../..
npm run start

Including --debug, omitting --debug, or replacing --debug with --release all result in a non-crashing better_sqlite3.node.

So it looks like the pre-built binary doesn’t work correctly.

I opened https://github.com/prebuild/prebuild/issues/309 to have this discussion in the right place.

Harumph–rebuilding resulted in the same behavior. Until this is properly resolved, I’d run https://github.com/WiseLibs/better-sqlite3/issues/1044#issuecomment-1693735596 in your postinstall.

I’ve kicked off a rebuild for the latest version, but I suspect the same binaries will be emitted. I’ll look into it a bit more tomorrow. @JoshuaWise if you’ve got any suggestions, that’d be great.