Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Electron 9 renderer crashes on sqlite module access when reloading the page #1370

Closed
dominic-simplan opened this issue Aug 13, 2020 · 40 comments
Labels
Milestone

Comments

@dominic-simplan
Copy link

Issue Details

  • node-sqlite3 version:
    • 5.0.0
  • Electron Version:
    • 9.2.0
  • Operating System:
    • Windows 10 (1909)

Actual Behavior

Since Electron 9 (tried with 9.1.2 and 9.2) seems like the renderer process (?) crashes when using the reload function. Initial loading of the page works fine, but when reloading, the page stays completely white and the DevTools report that it was disconnected from the page.
This seems to be related to the Electron flag allowRendererProcessReuse and this change in Electron. Since Electron 9, allowRendererProcessReuse is set to true by default. Switching it manually back to false fixes the described issue.

Looking at the crash dump (see below) and according to this comment on the Electron ticket I've created this seems to be related to the native sqlite module.

Here is the output of the crash dump with WinDbg:

Microsoft (R) Windows Debugger Version 10.0.20153.1000 AMD64
Copyright (c) Microsoft Corporation. All rights reserved.


Loading Dump File [C:\Users\xxx\AppData\Roaming\Electron\Crashpad\reports\99316939-67ae-470c-946b-5b8370ecc606.dmp]
User Mini Dump File: Only registers, stack and portions of memory are available

Symbol search path is: srv*
Executable search path is: 
Windows 10 Version 18362 (900) MP (16 procs) Free x64
Product: WinNt
Edition build lab: Windows NT 10.0.18362.900
Machine Name:
Debug session time: Tue Aug 11 11:35:25.000 2020 (UTC + 2:00)
System Uptime: not available
Process Uptime: 0 days 0:00:10.000
................................................................
.....
This dump file has an exception of interest stored in it.
The stored exception information can be accessed via .ecxr.
(18f0.82f0): Access violation - code c0000005 (first/second chance not available)
For analysis of this file, run !analyze -v
*** WARNING: Unable to verify checksum for ntdll.dll
*** WARNING: Unable to verify checksum for KERNELBASE.dll
ntdll!NtDelayExecution+0x14:
00007ffe`a653c6f4 c3              ret
0:000> !analyze -v
*******************************************************************************
*                                                                             *
*                        Exception Analysis                                   *
*                                                                             *
*******************************************************************************

*** WARNING: Unable to verify checksum for KERNEL32.DLL
*** WARNING: Unable to verify checksum for USER32.dll
*** WARNING: Unable to verify checksum for combase.dll

KEY_VALUES_STRING: 1

    Key  : AV.Fault
    Value: Write

    Key  : Analysis.CPU.mSec
    Value: 984

    Key  : Analysis.DebugAnalysisProvider.CPP
    Value: Create: 8007007e on HU-NB-370

    Key  : Analysis.DebugData
    Value: CreateObject

    Key  : Analysis.DebugModel
    Value: CreateObject

    Key  : Analysis.Elapsed.mSec
    Value: 783

    Key  : Analysis.Memory.CommitPeak.Mb
    Value: 275

    Key  : Analysis.System
    Value: CreateObject

    Key  : Timeline.Process.Start.DeltaSec
    Value: 10

    Key  : WER.Process.Version
    Value: 9.2.0.0


ADDITIONAL_XML: 1

OS_BUILD_LAYERS: 1

NTGLOBALFLAG:  0

PROCESS_BAM_CURRENT_THROTTLED: 0

PROCESS_BAM_PREVIOUS_THROTTLED: 0

CONTEXT:  (.ecxr)
rax=00007ff63763fe20 rbx=00007ffe3236fca8 rcx=000002cb58efddd0
rdx=00007ff637f5dec0 rsi=000002cb58d80460 rdi=000000dc32afb470
rip=00007ff638571b63 rsp=000000dc32afafb8 rbp=000000dc32afb170
 r8=000057570f33940d  r9=0000000000000001 r10=0000000000000000
r11=000000dc32afb010 r12=000057570da6e32d r13=00007ff636e74910
r14=0000000000000000 r15=000002cb58b79070
iopl=0         nv up ei pl nz na pe nc
cs=0033  ss=0000  ds=0000  es=0000  fs=0053  gs=002b             efl=00010202
electron!napi_delete_reference+0x53:
00007ff6`38571b63 48895008        mov     qword ptr [rax+8],rdx ds:00007ff6`3763fe28=8b48ce89484e74c9
Resetting default scope

EXCEPTION_RECORD:  (.exr -1)
ExceptionAddress: 00007ff638571b63 (electron!napi_delete_reference+0x0000000000000053)
   ExceptionCode: c0000005 (Access violation)
  ExceptionFlags: 00000000
NumberParameters: 2
   Parameter[0]: 0000000000000001
   Parameter[1]: 00007ff63763fe28
Attempt to write to address 00007ff63763fe28

PROCESS_NAME:  electron.exe

WRITE_ADDRESS:  00007ff63763fe28 

ERROR_CODE: (NTSTATUS) 0xc0000005 - Die Anweisung in 0x%p verwies auf Arbeitsspeicher bei 0x%p. Der Vorgang %s konnte im Arbeitsspeicher nicht durchgef hrt werden.

EXCEPTION_CODE_STR:  c0000005

EXCEPTION_PARAMETER1:  0000000000000001

EXCEPTION_PARAMETER2:  00007ff63763fe28

STACK_TEXT:  
000000dc`32afafb8 00007ff6`38571b2f     : ffffffff`fffffffe 000002cb`55c44630 00000000`00000009 fffffe10`dceb6d90 : electron!napi_delete_reference+0x53
000000dc`32afafc0 00007ffe`32227503     : 00007ff6`36e74910 00005757`0da6e32d 00006f55`8336d0db 00007ffe`3232a9ec : electron!napi_delete_reference+0x1f
000000dc`32afaff0 00007ff6`36e7490f     : 00005757`0da6e32d 00006f55`8336d0db 00007ffe`3232a9ec ffffffff`fffffffe : node_sqlite3+0x7503
000000dc`32afaff8 00005757`0da6e32d     : 00006f55`8336d0db 00007ffe`3232a9ec ffffffff`fffffffe 00007ffe`3222216b : electron!node_module_register+0x3ff
000000dc`32afb000 00006f55`8336d0db     : 00007ffe`3232a9ec ffffffff`fffffffe 00007ffe`3222216b 00006f55`8336d03b : 0x00005757`0da6e32d
000000dc`32afb008 00007ffe`3232a9ec     : ffffffff`fffffffe 00007ffe`3222216b 00006f55`8336d03b 000000dc`32afb470 : 0x00006f55`8336d0db
000000dc`32afb010 ffffffff`fffffffe     : 00007ffe`3222216b 00006f55`8336d03b 000000dc`32afb470 000000dc`32afb0a0 : node_sqlite3+0x10a9ec
000000dc`32afb018 00007ffe`3222216b     : 00006f55`8336d03b 000000dc`32afb470 000000dc`32afb0a0 000000dc`32afb490 : 0xffffffff`fffffffe
000000dc`32afb020 00006f55`8336d03b     : 000000dc`32afb470 000000dc`32afb0a0 000000dc`32afb490 00007ff6`00000000 : node_sqlite3+0x216b
000000dc`32afb028 000000dc`32afb470     : 000000dc`32afb0a0 000000dc`32afb490 00007ff6`00000000 00000000`00000000 : 0x00006f55`8336d03b
000000dc`32afb030 000000dc`32afb0a0     : 000000dc`32afb490 00007ff6`00000000 00000000`00000000 00006f55`8336d0bb : 0x000000dc`32afb470
000000dc`32afb038 000000dc`32afb490     : 00007ff6`00000000 00000000`00000000 00006f55`8336d0bb 000000dc`32afb400 : 0x000000dc`32afb0a0
000000dc`32afb040 00007ff6`00000000     : 00000000`00000000 00006f55`8336d0bb 000000dc`32afb400 000000dc`32afb0a0 : 0x000000dc`32afb490
000000dc`32afb048 00000000`00000000     : 00006f55`8336d0bb 000000dc`32afb400 000000dc`32afb0a0 00007ffe`3222b0c7 : 0x00007ff6`00000000


SYMBOL_NAME:  electron!napi_delete_reference+53

MODULE_NAME: electron

IMAGE_NAME:  electron.exe

STACK_COMMAND:  dt ntdll!LdrpLastDllInitializer BaseDllName ; dt ntdll!LdrpFailureData ; ~0s ; .ecxr ; kb

FAILURE_BUCKET_ID:  INVALID_POINTER_WRITE_c0000005_electron.exe!napi_delete_reference

OSPLATFORM_TYPE:  x64

OSNAME:  Windows 10

IMAGE_VERSION:  9.2.0.0

FAILURE_ID_HASH:  {95da9ce2-f2eb-0c22-0a13-18146f95472d}

Followup:     MachineOwner
---------

Any ideas what could be the issue?

@mohd-akram
Copy link
Contributor

See if #1368 fixes your issue. You can do npm install mohd-akram/node-sqlite3#fix-segfaults to try the version in the PR.

@pamtbaau
Copy link

pamtbaau commented Oct 22, 2020

@mohd-akram, Wanted to test above mentioned fix, but it has been removed. And 5.0.1 isn't released yet...

Any update on failing reload of renderer?

By the way, in the meantime, app.allowRendererProcessReuse = false; seems to be a temporary workaround.

@mohd-akram
Copy link
Contributor

@pamtbaau You can test with the master branch now npm install mapbox/node-sqlite3. You might need to remove the other version first.

@pamtbaau
Copy link

Darn, just removed Visual Studio and Python because of limited diskspace... And no pre-built binaries for sqlite3@5.0.1 and node@14.14.0 yet...

@pamtbaau
Copy link

TL;DR:

  • Patch 5.0.1 doesn't fix reload issue. Reload causes blank window.
  • Compiler generated file napi-v6-win32-x64\node_sqlite3.node while Electron expected napi-v3-win32-x64\node_sqlite3.node. Renaming the file made Electron happy, but reload causes blank window.

OK, downloaded a few gigs again for Visual Studio, tools and SDK... Took about 90 minutes to finish :-(

Ran npm install mapbox/node-sqlite3

Compilation seems to have worked well. File "C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\lib\binding\napi-v6-win32-x64\node_sqlite3.node" has been generated.

However, Electron throws an error:

Uncaught Error: Cannot find module 'C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\lib\binding\napi-v3-win32-x64\node_sqlite3.node'
Require stack:
- C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\lib\sqlite3-binding.js
- C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\lib\sqlite3.js
- C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\dist\index.html
    at Module._resolveFilename (internal/modules/cjs/loader.js:961)
    at Function.i._resolveFilename (electron/js2c/renderer_init.js:39)
    at Module._load (internal/modules/cjs/loader.js:844)
    at Function.Module._load (electron/js2c/asar.js:769)
    at Module.require (internal/modules/cjs/loader.js:1023)
    at require (internal/modules/cjs/helpers.js:77)
    at Object.<anonymous> (C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\lib\sqlite3-binding.js:4)
    at Object.<anonymous> (C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\lib\sqlite3-binding.js:7)
    at Module._compile (internal/modules/cjs/loader.js:1145)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1166)

Note that the file generated is: napi-v6-win32-x64\node_sqlite3.node
While the file requested by Electron is: napi-v3-win32-x64\node_sqlite3.node

When renaming napi-v6-win32-x64\node_sqlite3.node to napi-v3-win32-x64\node_sqlite3.node, sqlite works fine but reload causes empty window.

@mohd-akram
Copy link
Contributor

@pamtbaau Are you also getting a crash like the original post? If so, can you paste the crash log?

@pamtbaau
Copy link

pamtbaau commented Oct 23, 2020

@mohd-akram,

Did a fresh npm install. Contrary to my previous test, reload seems to be working most of the time.

  • It seems to go ok every time when using Ctrl+R (10/10)
  • It sometimes (2/10) breaks when reload gets initiated by a rebuild of the app triggering Electron to reload the js/html. After a subsequent change in the code, a reload will succeed.

When it fails with a blank screen and devtools showing 'DevTools' was disconnected from the page`, the following is printed in the terminal:

node-pre-gyp info This Node instance does not support builds for N-API version 6
FATAL ERROR: Error::Error napi_create_reference
 1: 00007FF6FD7345C6 node::Buffer::New+45414
 2: 00007FF6FD734789 node::Buffer::New+45865
 3: 00007FF6FD7345F9 node::Buffer::New+45465
 4: 00007FF6FE598F15 napi_fatal_error+149
 5: 00007FFAB052FDF7
 6: 00007FFAB052CFE2
 7: 00007FFAB0531ECD
 8: 00007FFAB0531B91
 9: 00007FFAB0542633
10: 00007FF6FE59AC26 napi_ref_threadsafe_function+1254
11: 00007FF6FE5B62FC uv_translate_sys_error+2380
12: 00007FF6FD754163 uv_run+307
13: 00007FF6FD71D0D7 node::EmitAsyncDestroy+85607
14: 00007FF6FD71D4B6 node::EmitAsyncDestroy+86598
15: 00007FF6FD70695D node::FreeEnvironment+13
16: 00007FF6FAAA59D8 v8::OutputStream::WriteHeapStatsChunk+130520
17: 00007FF6FD609A65 IsSandboxedProcess+2179013
18: 00007FF6FEE1219F uv_fs_poll_getpath+8729887
19: 00007FF6FE1208B3 GetHandleVerifier+9953331
20: 00007FF6FE1A5071 GetHandleVerifier+10495985
21: 00007FF6FE10C236 GetHandleVerifier+9869750
22: 00007FF6FE223494 GetHandleVerifier+11013140
23: 00007FF6FE222F05 GetHandleVerifier+11011717
24: 00007FF6FE1AD1CE GetHandleVerifier+10529102
25: 00007FF6FE1AF908 GetHandleVerifier+10539144
26: 00007FF6FD4B85CE IsSandboxedProcess+797486
27: 00007FF6FD5FB4E4 IsSandboxedProcess+2120260
28: 00007FF6FD6140DC IsSandboxedProcess+2221628
29: 00007FF6FD613F32 IsSandboxedProcess+2221202
30: 00007FF6FD5FAA04 IsSandboxedProcess+2117476
31: 00007FF6FE3D0725 GetHandleVerifier+12770981
32: 00007FF6FB429BD1 std::__1::vector<v8::CpuProfileDeoptFrame,std::__1::allocator<v8::CpuProfileDeoptFrame> >::vector<v8::CpuProfileDeoptFrame,std::__1::allocator<v8::CpuProfileDeoptFrame> >+1643473
33: 00007FF6FE3D0CDA GetHandleVerifier+12772442
34: 00007FF6FD04499A uv_cond_signal+1217946
35: 00007FF6FD88AD74 GetHandleVerifier+951540
36: 00007FF6FD889061 GetHandleVerifier+944097
37: 00007FF6FCEEBCBC uv_mutex_unlock+2521420
38: 00007FF6FD79BCE4 uv_gettimeofday+278804
39: 00007FF6FD79B9C8 uv_gettimeofday+278008
40: 00007FF6FD78C23B uv_gettimeofday+214635
41: 00007FF6FD79C2DE uv_gettimeofday+280334
42: 00007FF6FCED5B6C uv_mutex_unlock+2430972
43: 00007FF6FD61B994 IsSandboxedProcess+2252532
44: 00007FF6FC2C82E1 v8_inspector::V8StackTraceId::ToString+5677153
45: 00007FF6FD45BB0B IsSandboxedProcess+417899
46: 00007FF6FB55CDEE v8::CpuProfilingOptions::max_samples+784398
47: 00007FF6FA93149F Ordinal0+5279
48: 00007FF7009CEE12 uv_random+16903298
49: 00007FFAE3917034 BaseThreadInitThunk+20
50: 00007FFAE3ABCEC1 RtlUserThreadStart+33

@mohd-akram
Copy link
Contributor

You need to build the package for electron since there aren't prebuilt binaries. See the instructions here. Try running:

npm install --save-dev electron-rebuild
# Every time you run "npm install", run this:
./node_modules/.bin/electron-rebuild

@pamtbaau
Copy link

pamtbaau commented Oct 23, 2020

Hm, I'm confused... I have in my package.json "postinstall": "electron-builder install-app-deps" and VC++ is being called when running npm install mapbox/node-sqlite3

To quote electron-builder:

To ensure your native dependencies are always matched electron version, simply add script "postinstall": "electron-builder install-app-deps" to your package.json.

Output running npm install mapbox/node-sqlite3:

> sqlite3@5.0.1 install C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using request for node-pre-gyp https download
node-pre-gyp WARN Tried to download(403): https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v5.0.1/napi-v6-win32-x64.tar.gz
node-pre-gyp WARN Pre-built binaries not found for sqlite3@5.0.1 and node@14.14.0 (node-v83 ABI, unknown) (falling back to source compile with node-gyp)
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  nothing.c
  win_delay_load_hook.cc
  nothing.vcxproj -> C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\build\Release\\nothing
  .lib
  unpack_sqlite_dep
  sqlite3.c
  win_delay_load_hook.cc
  sqlite3.vcxproj -> C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\build\Release\\sqlite3
  .lib
  backup.cc
  database.cc
  node_sqlite3.cc
  statement.cc
  win_delay_load_hook.cc
     Creating library C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\build\Release\node_sq
  lite3.lib and object C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\build\Release\node_s
  qlite3.exp
  node_sqlite3.vcxproj -> C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\build\Release\\no
  de_sqlite3.node
  Copying C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\build\Release\/node_sqlite3.node
  to C:/Users/xxx/Documents/Development/Typescript/Electron/electron-test/node_modules/sqlite3/lib/binding/napi-v6-win32-x64\node_sql
  ite3.node
          1 file(s) copied.
n

I'll try your suggestion though....

@pamtbaau
Copy link

pamtbaau commented Oct 23, 2020

Even more confused...

  • Removed electron-builder
  • Removed script "postinstall": "electron-builder install-app-deps"
  • Installed electron-rebuild
  • Run npm install mapbox/node-sqlite3
    • Compiler is being called and binding/napi-v6-win32-x64\node_sqlite3.node is being generated
  • Running npx electron-rebuild throws errors. See below.

Another try:

  • Removed node-modules
  • Run npm install
    • Compiler is being called
    • All is well
  • Run npx electron-rebuild
    • Same errors being thrown.

Errors during compilation using npx electron-rebuild

\ Building module: sqlite3, Completed: 0Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
                                          nothing.c
- Building module: sqlite3, Completed: 0  win_delay_load_hook.cc
- Building module: sqlite3, Completed: 0  nothing.vcxproj -> C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\build\Release\\nothing.lib
\ Building module: sqlite3, Completed: 0  unpack_sqlite_dep
- Building module: sqlite3, Completed: 0  sqlite3.c
| Building module: sqlite3, Completed: 0  win_delay_load_hook.cc
| Building module: sqlite3, Completed: 0  sqlite3.vcxproj -> C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\build\Release\\sqlite3.lib
- Building module: sqlite3, Completed: 0  backup.cc
| Building module: sqlite3, Completed: 0c:\users\xxx\documents\development\typescript\electron\electron-test\node_modules\node-addon-api\napi-inl.h(752): error C3861: 'napi_create_bigint_int64': identifier not found [C:
\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\build\node_sqlite3.vcxproj]
c:\users\xxx\documents\development\typescript\electron\electron-test\node_modules\node-addon-api\napi-inl.h(759): error C3861: 'napi_create_bigint_uint64': identifier not found [C
:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\build\node_sqlite3.vcxproj]
c:\users\xxx\documents\development\typescript\electron\electron-test\node_modules\node-addon-api\napi-inl.h(766): error C3861: 'napi_create_bigint_words': identifier not found [C:
\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\build\node_sqlite3.vcxproj]
c:\users\xxx\documents\development\typescript\electron\electron-test\node_modules\node-addon-api\napi-inl.h(779): error C3861: 'napi_get_value_bigint_int64': identifier not found
[C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\build\node_sqlite3.vcxproj]
c:\users\xxx\documents\development\typescript\electron\electron-test\node_modules\node-addon-api\napi-inl.h(787): error C3861: 'napi_get_value_bigint_uint64': identifier not found
 [C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\build\node_sqlite3.vcxproj]
c:\users\xxx\documents\development\typescript\electron\electron-test\node_modules\node-addon-api\napi-inl.h(795): error C3861: 'napi_get_value_bigint_words': identifier not found
[C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\build\node_sqlite3.vcxproj]
c:\users\xxx\documents\development\typescript\electron\electron-test\node_modules\node-addon-api\napi-inl.h(802): error C3861: 'napi_get_value_bigint_words': identifier not found
[C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\build\node_sqlite3.vcxproj]
× Rebuild Failed

An unhandled error occurred inside electron-rebuild
node-gyp failed to rebuild 'C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3'.
Error: `C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe` failed with exit code: 1



Error: node-gyp failed to rebuild 'C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3'.
Error: `C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe` failed with exit code: 1


    at ModuleRebuilder.rebuildNodeGypModule (C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\electron-rebuild\lib\src\module-rebuilder.js:193:19)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Rebuilder.rebuildModuleAt (C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\electron-rebuild\lib\src\rebuild.js:183:9)
    at async Rebuilder.rebuild (C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\electron-rebuild\lib\src\rebuild.js:145:17)
    at async C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\electron-rebuild\lib\src\cli.js:145:9

@pamtbaau
Copy link

pamtbaau commented Nov 4, 2020

@mohd-akram , Any news on this issue you could share?

@mohd-akram
Copy link
Contributor

I think the issue is that the Node.js version you have installed is newer than the Electron one. What Node.js version are you using? I encountered a similar thing while working on #1367 (see #1367 (comment)) and had to set the Node.js versions of the CI to match Electron. I guess you could confirm this by using something like nvm - you'd need to use a version of Node.js < 12.17.0. I'm not sure what the workaround would be to build locally for newer versions, but it should work once 5.0.1 is released and pre-built binaries are available.

@pamtbaau
Copy link

pamtbaau commented Nov 4, 2020

Was using node v14.x and downgraded to v12.16.3.

Steps:

  • Removed /node_modules
  • Reinstalled all dependencies
    • Using "sqlite3": "github:mapbox/node-sqlite3"
    • NB. No Visual Studio compiler, nor Python available.
  • Starting Electron app goes well
  • Reload fails
  • Add app.allowRendererProcessReuse = false; to index.js and reload succeeds.

@mohd-akram
Copy link
Contributor

How did the install complete without a compiler?

@pamtbaau
Copy link

pamtbaau commented Nov 4, 2020

You may call me stupid, but I just don't know what is going on under the hood...

This is a section form the output of npm install:

[stuff omitted]

> sqlite3@github:mapbox/node-sqlite3#833f5cc1332b9213a17873f42a3d3a18dca5afc1 install C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3
> node-pre-gyp install --fallback-to-build
node-pre-gyp WARN Using request for node-pre-gyp https download
[sqlite3] Success: "C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\lib\binding\napi-v3-win32-x64\node_sqlite3.node" is installed via remote

[stuff omitted]

> electron-builder install-app-deps

  • electron-builder  version=22.9.1
  • loaded configuration  file=package.json ("build" field)
  • rebuilding native dependencies  dependencies=sqlite3@5.0.1 platform=win32 arch=x64

@mohd-akram
Copy link
Contributor

It says "rebuilding native dependencies" and it seems to be using the correct napi version this time (v3). Perhaps you have the build tools installed. Does npx electron-rebuild still fail? What's the error you get when the reload fails? Is it still FATAL ERROR: Error::Error napi_create_reference? Can you post the full log of the reload error?

@pamtbaau
Copy link

pamtbaau commented Nov 4, 2020

Perhaps you have the build tools installed.

I cannot find any references to VS compiler, SDK's etc on disk nor in control panel or settings/apps.

Does npx electron-rebuild still fail?

electron-rebuild is no longer in package.json

@pamtbaau
Copy link

pamtbaau commented Nov 6, 2020

@mohd-akram Installed Python and VS Studio again...

TLDR; Two scenarios tested:

  • Without electron-rebuild
    • Initial start electron: app is shown
    • After 1st reload, empty screen
    • It seems there are no more reloads (judging from the messages send to terminal)
  • With electron-rebuild
    • Initial start electron: app is shown
    • After 1st reload, empty screen
    • It seems to keep reloading
    • After x reloads error in terminal:

      "FATAL ERROR: Error::Error napi_create_reference"

Env:

  • Windows 10 20H2
  • Node v12.16.3
  • Electron v10.1.3
  • Typescript v3.9.6

package.json

  "scripts": {
    "ng": "ng",
    "start": "electron .",
    "build:watch": "ng build --base-href ./ --watch",
    "postinstall": "electron-builder install-app-deps"
  },
  "dependencies": {
    "@angular-builders/custom-webpack": "^10.0.1",
    "@angular/animations": "~10.1.5",
    "@angular/common": "~10.1.5",
    "@angular/compiler": "~10.1.5",
    "@angular/core": "~10.1.5",
    "@angular/forms": "~10.1.5",
    "@angular/platform-browser": "~10.1.5",
    "@angular/platform-browser-dynamic": "~10.1.5",
    "@angular/router": "~10.1.5",
    "electron-reload": "^1.5.0",
    "rxjs": "^6.6.3",
    "sqlite3": "github:mapbox/node-sqlite3",
    "tslib": "^2.0.2",
    "zone.js": "~0.11.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.1001.5",
    "@angular/cli": "~10.1.5",
    "@angular/compiler-cli": "~10.1.5",
    "@angular/language-service": "~10.1.5",
    "@types/node": "^14.11.5",
    "@types/sqlite3": "^3.1.6",
    "electron": "^10.1.3",
    "electron-builder": "^22.8.1",
    "electron-rebuild": "^2.3.2",
    "ts-node": "~9.0.0",
    "tslint": "~6.1.3",
    "typescript": "~4.0.3"
  }

angular app.component

import { Component } from '@angular/core';
import { Database } from 'sqlite3';

@Component({
    selector: 'app-root',
    templateUrl: 'app.component.html',
})
export class AppComponent {

    constructor() {
        new Database('C:/Users/xxx/Documents/qq.db', (err) => {
            if (err) {
                console.log('Failed to open Db.');
                throw err;
            } else {
                console.log('Db successfully opened.');
            }
        });
    }
}
  1. npm install

    PS C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test> npm install
    
    > lzma-native@6.0.1 install C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\lzma-native
    > node-pre-gyp install --fallback-to-build && rimraf build
    
    node-pre-gyp WARN Using request for node-pre-gyp https download
    [lzma-native] Success: "C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\lzma-native\binding-v6.0.1-n-api-win32-x64\lzma_native.node" is installed via remote
    
    > sqlite3@5.0.1 install C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3
    > node-pre-gyp install --fallback-to-build
    
    node-pre-gyp WARN Using request for node-pre-gyp https download
    [sqlite3] Success: "C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\lib\binding\napi-v3-win32-x64\node_sqlite3.node" is installed via remote
    
    > core-js@3.6.4 postinstall C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\core-js
    > node -e "try{require('./postinstall')}catch(e){}"
    
    Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
    
    The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
    > https://opencollective.com/core-js
    > https://www.patreon.com/zloirock
    
    Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
    
    
    > core-js@3.6.5 postinstall C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\global-agent\node_modules\core-js
    > node -e "try{require('./postinstall')}catch(e){}"
    
    
    > @angular/cli@10.1.5 postinstall C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\@angular\cli
    > node ./bin/postinstall/script.js
    
    
    > electron@10.1.3 postinstall C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\electron
    > node install.js
    
    
    > angular-cli-electron-sqlite-bootstrap@1.0.2 postinstall C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test
    > electron-builder install-app-deps
    
    • electron-builder  version=22.8.1
    • rebuilding native dependencies  dependencies=sqlite3@5.0.1 platform=win32 arch=x64
    npm WARN angular-cli-electron-sqlite-bootstrap@1.0.2 No repository field.
    npm WARN angular-cli-electron-sqlite-bootstrap@1.0.2 No license field.
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\webpack-dev-server\node_modules\fsevents):
    npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\watchpack-chokidar2\node_modules\fsevents):
    npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules\fsevents):
    npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
    
    added 1626 packages from 753 contributors and audited 1632 packages in 649.675s
    
    87 packages are looking for funding
    run `npm fund` for details
    
    found 2 high severity vulnerabilities
    run `npm audit fix` to fix them, or `npm audit` for details
    PS C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test>
    
  2. Generated binding

    \node_modules\sqlite3\lib\binding\napi-v3-win32-x64
    
  3. Starting Electron

    • window:

      • displays application
    • console:

      • app.component.ts:16

      Db successfully opened.

    • terminal:

      • node-pre-gyp info This Node instance does not support builds for N-API version 6
      • node-pre-gyp info This Node instance does not support builds for N-API version 6
    • Reload:

      • window: blank window
      • console:

        "DevTools was disconnected from the page. Once page is reloaded, DevTools will automatically reconnect."

      • terminal:
        • node-pre-gyp info This Node instance does not support builds for N-API version 6
        • node-pre-gyp info This Node instance does not support builds for N-API version 6
        • node-pre-gyp info This Node instance does not support builds for N-API version 6
        • node-pre-gyp info This Node instance does not support builds for N-API version 6
    • Subsequent reload: no more reloads

      • window: blank window
      • console: blank
      • terminal:
        • node-pre-gyp info This Node instance does not support builds for N-API version 6
        • node-pre-gyp info This Node instance does not support builds for N-API version 6
        • node-pre-gyp info This Node instance does not support builds for N-API version 6
        • node-pre-gyp info This Node instance does not support builds for N-API version 6
  4. npx electron-rebuild

    PS C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test> npx electron-rebuild
    | Building module: sqlite3, Completed: 0gyp info find Python using Python version 2.7.15 found at "C:\Users\xxx\.windows-build-tools\python27\python.exe"
    / Building module: sqlite3, Completed: 0gyp http GET https://www.electronjs.org/headers/v10.1.3/node-v10.1.3-headers.tar.gz
    \ Building module: sqlite3, Completed: 0gyp http 200 https://www.electronjs.org/headers/v10.1.3/node-v10.1.3-headers.tar.gz
    - Building module: sqlite3, Completed: 0gyp http GET https://www.electronjs.org/headers/v10.1.3/SHASUMS256.txt
    gyp http GET https://www.electronjs.org/headers/v10.1.3/win-x64/node.lib
    gyp http GET https://www.electronjs.org/headers/v10.1.3/win-x86/node.lib
    gyp http GET https://www.electronjs.org/headers/v10.1.3/win-arm64/node.lib
    - Building module: sqlite3, Completed: 0gyp http 200 https://www.electronjs.org/headers/v10.1.3/SHASUMS256.txt
    \ Building module: sqlite3, Completed: 0gyp http 200 https://www.electronjs.org/headers/v10.1.3/win-x86/node.lib
    gyp http 200 https://www.electronjs.org/headers/v10.1.3/win-arm64/node.lib
    gyp http 200 https://www.electronjs.org/headers/v10.1.3/win-x64/node.lib
    | Building module: sqlite3, Completed: 0gyp info find VS using VS2017 (15.9.28307.1274) found at:
    gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools"
    gyp info find VS run with --verbose for detailed information
    gyp info spawn C:\Users\xxx\.windows-build-tools\python27\python.exe
    gyp info spawn args [
    gyp info spawn args   'C:\\Users\\xxx\\Documents\\Development\\Typescript\\Electron\\electron-test\\node_modules\\electron-rebuild\\node_modules\\node-gyp\\gyp\\gyp_main.py',
    gyp info spawn args   'binding.gyp',
    gyp info spawn args   '-f',
    gyp info spawn args   'msvs',
    gyp info spawn args   '-I',
    gyp info spawn args   'C:\\Users\\xxx\\Documents\\Development\\Typescript\\Electron\\electron-test\\node_modules\\sqlite3\\build\\config.gypi',
    gyp info spawn args   '-I',
    gyp info spawn args   'C:\\Users\\xxx\\Documents\\Development\\Typescript\\Electron\\electron-test\\node_modules\\electron-rebuild\\node_modules\\node-gyp\\addon.gypi',
    gyp info spawn args   '-I',
    gyp info spawn args   'C:\\Users\\xxx\\Documents\\Development\\Typescript\\Electron\\electron-test\\node_modules\\sqlite3\\10.1.3\\include\\node\\common.gypi',
    gyp info spawn args   '-Dlibrary=shared_library',
    gyp info spawn args   '-Dvisibility=default',
    gyp info spawn args   '-Dnode_root_dir=C:\\Users\\xxx\\Documents\\Development\\Typescript\\Electron\\electron-test\\node_modules\\sqlite3\\10.1.3',
    gyp info spawn args   '-Dnode_gyp_dir=C:\\Users\\xxx\\Documents\\Development\\Typescript\\Electron\\electron-test\\node_modules\\electron-rebuild\\node_modules\\node-gyp',
    gyp info spawn args   '-Dnode_lib_file=C:\\\\Users\\\\xxx\\\\Documents\\\\Development\\\\Typescript\\\\Electron\\\\electron-test\\\\node_modules\\\\sqlite3\\\\10.1.3\\\\<(target_arch)\\\\node.lib',
    gyp info spawn args   '-Dmodule_root_dir=C:\\Users\\xxx\\Documents\\Development\\Typescript\\Electron\\electron-test\\node_modules\\sqlite3',
    gyp info spawn args   '-Dnode_engine=v8',
    gyp info spawn args   '--depth=.',
    gyp info spawn args   '--no-parallel',
    gyp info spawn args   '--generator-output',
    gyp info spawn args   'C:\\Users\\xxx\\Documents\\Development\\Typescript\\Electron\\electron-test\\node_modules\\sqlite3\\build',
    gyp info spawn args   '-Goutput_dir=.'
    gyp info spawn args ]
    \ Building module: sqlite3, Completed: 0gyp info spawn C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe
    gyp info spawn args [
    gyp info spawn args   'build/binding.sln',
    gyp info spawn args   '/clp:Verbosity=minimal',
    gyp info spawn args   '/nologo',
    gyp info spawn args   '/p:Configuration=Release;Platform=x64',
    gyp info spawn args   map: [Function]
    gyp info spawn args ]
    | Building module: sqlite3, Completed: 0Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
    - Building module: sqlite3, Completed: 0  nothing.c
    | Building module: sqlite3, Completed: 0  win_delay_load_hook.cc
    - Building module: sqlite3, Completed: 0  nothing.vcxproj -> C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\build\Release\\nothing.lib
    | Building module: sqlite3, Completed: 0  unpack_sqlite_dep
    - Building module: sqlite3, Completed: 0  sqlite3.c
    | Building module: sqlite3, Completed: 0  win_delay_load_hook.cc
    \ Building module: sqlite3, Completed: 0  sqlite3.vcxproj -> C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\build\Release\\sqlite3.lib
    / Building module: sqlite3, Completed: 0  backup.cc
    - Building module: sqlite3, Completed: 0  database.cc
    | Building module: sqlite3, Completed: 0  node_sqlite3.cc
    | Building module: sqlite3, Completed: 0  statement.cc
    - Building module: sqlite3, Completed: 0  win_delay_load_hook.cc
    - Building module: sqlite3, Completed: 0     Creating library C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\build\Release\node_sqlite3.lib and object C:\Users\xxx\Documents\Development\
    Typescript\Electron\electron-test\node_modules\sqlite3\build\Release\node_sqlite3.exp
    Generating code
    / Building module: sqlite3, Completed: 0  All 4920 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
    \ Building module: sqlite3, Completed: 0  Finished generating code
    / Building module: sqlite3, Completed: 0  node_sqlite3.vcxproj -> C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\build\Release\\node_sqlite3.node
    \ Building module: sqlite3, Completed: 0  Copying C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test\node_modules\sqlite3\build\Release\/node_sqlite3.node to C:\Users\xxx\Documents\Development\Typescript\Electro
    n\electron-test\node_modules\sqlite3\lib\binding\napi-v{napi_build_version}-win32-x64
    | Building module: sqlite3, Completed: 0          1 file(s) copied.
    ? Rebuild Complete
    PS C:\Users\xxx\Documents\Development\Typescript\Electron\electron-test>
    
  5. Generated binding

    • napi-v{napi_build_version}-win32-x64
    • napi-v3-win32-x64
  6. Renamed new binding

  7. Recompile application

  8. Starting Electron

    • window: as expected
    • console: app.component.ts:16 Db successfully opened.
    • terminal:
      • node-pre-gyp info This Node instance does not support builds for N-API version 6
      • node-pre-gyp info This Node instance does not support builds for N-API version 6
  9. Reload

    • window: blank

    • console: blank with popup

      "DevTools was disconnected from the page.
      Once page is reloaded, DevTools will automatically reconnect."

    • terminal:

      • node-pre-gyp info This Node instance does not support builds for N-API version 6
      • node-pre-gyp info This Node instance does not support builds for N-API version 6
      • node-pre-gyp info This Node instance does not support builds for N-API version 6
      • node-pre-gyp info This Node instance does not support builds for N-API version 6
  10. Subsquent reloads

    Alternating blank screen and succesful reload

    • window: blank

    • console:

      "DevTools was disconnected from the page.
      Once page is reloaded, DevTools will automatically reconnect."

    • terminal:

      • node-pre-gyp info This Node instance does not support builds for N-API version 6
      • node-pre-gyp info This Node instance does not support builds for N-API version 6
      • node-pre-gyp info This Node instance does not support builds for N-API version 6
      • node-pre-gyp info This Node instance does not support builds for N-API version 6
      • node-pre-gyp info This Node instance does not support builds for N-API version 6
      • node-pre-gyp info This Node instance does not support builds for N-API version 6
      • node-pre-gyp info This Node instance does not support builds for N-API version 6
      • node-pre-gyp info This Node instance does not support builds for N-API version 6
      • node-pre-gyp info This Node instance does not support builds for N-API version 6
      • node-pre-gyp info This Node instance does not support builds for N-API version 6
  11. After x reloads

    • Terminal:
          FATAL ERROR: Error::Error napi_create_reference
          1: 00007FF694582E06 node::Buffer::New+45830
          2: 00007FF694582FC9 node::Buffer::New+46281
          3: 00007FF694582E39 node::Buffer::New+45881
          4: 00007FF6953E74B5 napi_fatal_error+149
          5: 00007FF957311DE7 Napi::Error::Fatal+23 [c:\users\xxx\documents\development\typescript\electron\electron-test\node_modules\node-addon-api\napi-inl.h]:L2252
          6: 00007FF957311D65 Napi::Error::New+341 [c:\users\xxx\documents\development\typescript\electron\electron-test\node_modules\node-addon-api\napi-inl.h]:L2240
          7: 00007FF95731CC91 node_sqlite3::Database::Work_AfterOpen+1537 [c:\users\xxx\documents\development\typescript\electron\electron-test\node_modules\sqlite3\src\database.cc]:L204
          8: 00007FF6953E9176 napi_ref_threadsafe_function+1174
          9: 00007FF69540484C uv_translate_sys_error+2380
          10: 00007FF6945A29A3 uv_run+307
          11: 00007FF69456B777 node::EmitAsyncDestroy+84871
          12: 00007FF69456BB56 node::EmitAsyncDestroy+85862
          13: 00007FF6945554AD node::FreeEnvironment+13
          14: 00007FF6918F4A65 v8::OutputStream::WriteHeapStatsChunk+130229
          15: 00007FF6944585B5 IsSandboxedProcess+2178773
          16: 00007FF695C606EF uv_fs_poll_getpath+8729887
          17: 00007FF694F6F0F3 GetHandleVerifier+9953331
          18: 00007FF694FF38B1 GetHandleVerifier+10495985
          19: 00007FF694F5AA76 GetHandleVerifier+9869750
          20: 00007FF695071CD4 GetHandleVerifier+11013140
          21: 00007FF695071745 GetHandleVerifier+11011717
          22: 00007FF694FFBA0E GetHandleVerifier+10529102
          23: 00007FF694FFE148 GetHandleVerifier+10539144
          24: 00007FF69430711E IsSandboxedProcess+797246
          25: 00007FF69444A034 IsSandboxedProcess+2120020
          26: 00007FF694462C2C IsSandboxedProcess+2221388
          27: 00007FF694462A82 IsSandboxedProcess+2220962
          28: 00007FF694449554 IsSandboxedProcess+2117236
          29: 00007FF69521EF65 GetHandleVerifier+12770981
          30: 00007FF692278851 std::__1::vector<v8::CpuProfileDeoptFrame,std::__1::allocator<v8::CpuProfileDeoptFrame> >::vector<v8::CpuProfileDeoptFrame,std::__1::allocator<v8::CpuProfileDeoptFrame> >+1643473
          31: 00007FF69521F51A GetHandleVerifier+12772442
          32: 00007FF693E9350A uv_cond_signal+1217946
          33: 00007FF6946D95B4 GetHandleVerifier+951540
          34: 00007FF6946D78A1 GetHandleVerifier+944097
          35: 00007FF693D3A82C uv_mutex_unlock+2521420
          36: 00007FF6945EA524 uv_gettimeofday+278804
          37: 00007FF6945EA208 uv_gettimeofday+278008
          38: 00007FF6945DAA7B uv_gettimeofday+214635
          39: 00007FF6945EAB1E uv_gettimeofday+280334
          40: 00007FF693D246DC uv_mutex_unlock+2430972
          41: 00007FF69446A4E4 IsSandboxedProcess+2252292
          42: 00007FF693116F61 v8_inspector::V8StackTraceId::ToString+5677153
          43: 00007FF6942AA74B IsSandboxedProcess+417899
          44: 00007FF6923ABA6E v8::Location::GetColumnNumber+784398
          45: 00007FF69178149F Ordinal0+5279
          46: 00007FF69781D042 uv_random+16902530
          47: 00007FF97EEB7034 BaseThreadInitThunk+20
          48: 00007FF97F87CEC1 RtlUserThreadStart+33
          ```
      

@vortrefflich
Copy link

vortrefflich commented Nov 23, 2020

Hello, I also had troubles in reload-error.

Version information
node v14.15.1
electron v11.0.2
sqlite3 v5.0.0

Problem code

const db = require('sqlite3').verbose(); // <-- Error was occurred in this line when reloading.

Solution
"app.allowRendererProcessReuse = false"

By following your ideas, I added the code, and now it works.

Discussion
"allowRendererProcessReuse" will be deprecated.

@pamtbaau
Copy link

@vortrefflich, allowRendererProcessReuse has indeed been deprecated, but if I recall correctly, Electron postponed its removal to give 3th party libraries more time to adapt.

Also, be advised that you might see an accumulation of Electron processes by setting app.allowRendererProcessReuse = false. It brings my Windows 10 system down on its knees...

@vortrefflich
Copy link

Dear @pamtbaau.
This problem is from lazy-update of Nodejs.
There is a solution that add nodejs-addon code, but it is based on C so it quite looked hard to adopt.
(node::AddEnvironmentCleanupHook(), https://nodejs.org/api/addons.html)

As a result,
I solved this problem by installing newer version of sqlite3 (5.0.1)

Reference

@pamtbaau
Copy link

pamtbaau commented Nov 23, 2020

@vortrefflich, I did test 5.0.1 and downgraded Node as suggested, but no success... Issue remains.

Which OS are you using?

@vortrefflich
Copy link

@pamtbaau, I installed all the modules as latest version.
(1) install node-v14.15.1 (manually)
(2) install electron-v11.0.2 and other related modules (cli)
(3) install sqlite3-v5.0.1 (cli, https request)

My computer works in Win10 x64.

@pamtbaau
Copy link

@vortrefflich, Still cannot get it to work...

If it is not too much asked, would you mind trying a minimal Electron/Angular/Sqlite repo I've created? Or, if you have got a repo I can test, that will be fine too.

@vortrefflich
Copy link

vortrefflich commented Nov 25, 2020

Dear @pamtbaau,
I tested your code on two computers.

  • Result: 1 succeeded and 1 failed.
  • Difference:
    • Failed computer: It installed node_sqlite3.node in "node_modules/sqlite3/lib/binding/napi-v3-win32-x64".
    • Succeeded computer: It installed in "node_modules/sqlite3/lib/binding/napi-v6-win32-x64".
  • Failure type: Error occurred

TEST 2 - to solve napi-v3-win32-x64 error.

  • Method: change code in "node_modules/sqlite3/package.json"
    from "napi_versions": [3, 6]
    to "napi_versions": [3]
  • Result: The system succeeded in loading electron, but error was occurred when refresh the window.

Conclusion - The "node_sqlite3.node" file should be installed into "node_modules/sqlite3/lib/binding/napi-v6-win32-x64"

@pamtbaau
Copy link

@vortrefflich, Thanks for the time and effort spent to test my sample repo. I appreciate it.

Curious about the differences between your two machines...

Tried jumping several hoops again, but no success. In the mean time, I'll stick to app.allowRendererProcessReuse = false

NB. Your conclusion seems to contradict the result of the succeeded computer which generated napi-v3-win32-x64

@vortrefflich
Copy link

@pamtbaau,
Oh, sorry. I fixed wrong words.
napi-v6 should be installed.
And All the test with sqlite3 5.0.1 was proceeded without setting of "app.allowRendererProcessReuse".
In my case, 5.0.1 works fine.

@MatteoMeil
Copy link

MatteoMeil commented Dec 29, 2020

Just tested with electron@^11.1.1 and it seems to work and not crash when (force) reloading.
At the moment (2020-12-29) the npm package seems to not be updated thus, if you install it via npm i sqlite3 it won't work unless you set app.allowRendererProcessReuse = false.

It must be installed via npm install mapbox/node-sqlite3 and you must have build tools installed.

Optionally you can run electron-rebuild sqlite3

Environment:

  • Win10 20H2 x64
  • Visual Studio 2019
  • Node 14.5.0
  • Electron 11.1.1

@bpasero
Copy link
Contributor

bpasero commented Feb 16, 2021

I have seen such as crash in VSCode when trying to adopt latest SQLite, whenever I close VSCode, a crash would occur. Ever since we updated to Electron 11 though, I cannot reproduce the crash anymore.

Stack:

Thread 0 (crashed)
 0  libsystem_kernel.dylib!__pthread_kill + 0xa
    rax = 0x0000000000000000   rdx = 0x0000000000000000
    rcx = 0x00007ffee7e75e18   rbx = 0x00000001134e9dc0
    rsi = 0x0000000000000006   rdi = 0x0000000000000307
    rbp = 0x00007ffee7e75e40   rsp = 0x00007ffee7e75e18
     r8 = 0x0000000000000000    r9 = 0x0000000000989680
    r10 = 0x00000001134e9dc0   r11 = 0x0000000000000246
    r12 = 0x0000000000000307   r13 = 0x0000000000000050
    r14 = 0x0000000000000006   r15 = 0x0000000000000016
    rip = 0x00007fff708dd33a
    Found by: given as instruction pointer in context
 1  libsystem_c.dylib!__abort + 0x8b
    rbp = 0x00007ffee7e75e90   rsp = 0x00007ffee7e75e50
    rip = 0x00007fff708648a2
    Found by: previous frame's frame pointer
 2  libsystem_c.dylib!abort + 0x87
    rbp = 0x00007ffee7e75ed0   rsp = 0x00007ffee7e75ea0
    rip = 0x00007fff70864817
    Found by: previous frame's frame pointer
 3  libsystem_malloc.dylib!malloc_vreport + 0x224
    rbp = 0x00007ffee7e75f30   rsp = 0x00007ffee7e75ee0
    rip = 0x00007fff7095a50b
    Found by: previous frame's frame pointer
 4  libsystem_malloc.dylib!malloc_report + 0x97
    rbp = 0x00007ffee7e76010   rsp = 0x00007ffee7e75f40
    rip = 0x00007fff7095d40f
    Found by: previous frame's frame pointer
 5  Electron Framework!napi_delete_reference [js_native_api_v8.cc : 252 + 0x9]
    rbp = 0x00007ffee7e76030   rsp = 0x00007ffee7e76020
    rip = 0x000000010dd6e60c
    Found by: previous frame's frame pointer
 6  sqlite.node + 0x15795
    rbp = 0x00007ffee7e76050   rsp = 0x00007ffee7e76040
    rip = 0x000000011802c795
    Found by: previous frame's frame pointer
 7  Electron Framework!void napi_env__::CallIntoModule<napi_env__::~napi_env__()::'lambda'(napi_env__*)&, void napi_env__::CallIntoModuleThrow<napi_env__::~napi_env__()::'lambda'(napi_env__*)>(napi_env__::~napi_env__()::'lambda'(napi_env__*)&&)::'lambda'(napi_env__*, v8::Local<v8::Value>)>(napi_env__::~napi_env__()::'lambda'(napi_env__*)&&, void napi_env__::CallIntoModuleThrow<napi_env__::~napi_env__()::'lambda'(napi_env__*)>(napi_env__::~napi_env__()::'lambda'(napi_env__*)&&)::'lambda'(napi_env__*, v8::Local<v8::Value>)&&) [js_native_api_v8.h : 27 + 0x6]
    rbp = 0x00007ffee7e76080   rsp = 0x00007ffee7e76060
    rip = 0x000000010dd864f9
    Found by: previous frame's frame pointer
 8  Electron Framework!napi_env__::~napi_env__() [js_native_api_v8.h : 59 + 0x8]
    rbp = 0x00007ffee7e760b0   rsp = 0x00007ffee7e76090
    rip = 0x000000010dd86482
    Found by: previous frame's frame pointer
 9  Electron Framework!node_napi_env__::~node_napi_env__() [node_api.cc : 14 + 0x5]
    rbp = 0x00007ffee7e760d0   rsp = 0x00007ffee7e760c0
    rip = 0x000000010dd8630e
    Found by: previous frame's frame pointer
10  Electron Framework!node::Environment::RunCleanup() [env.cc : 614 + 0x2]
    rbp = 0x00007ffee7e76140   rsp = 0x00007ffee7e760e0
    rip = 0x000000010dd5abaf
    Found by: previous frame's frame pointer
11  Electron Framework!node::FreeEnvironment(node::Environment*) [environment.cc : 291 + 0x5]
    rbp = 0x00007ffee7e76160   rsp = 0x00007ffee7e76150
    rip = 0x000000010dd2828e
    Found by: previous frame's frame pointer
12  Electron Framework!electron::ElectronBrowserMainParts::PostMainMessageLoopRun() [memory : 2378 + 0x8]
    rbp = 0x00007ffee7e761b0   rsp = 0x00007ffee7e76170
    rip = 0x0000000107e9569f
    Found by: previous frame's frame pointer
13  Electron Framework!content::BrowserMainLoop::ShutdownThreadsAndCleanUp() [browser_main_loop.cc : 1095 + 0x6]
    rbp = 0x00007ffee7e76240   rsp = 0x00007ffee7e761c0
    rip = 0x00000001099cb5d1
    Found by: previous frame's frame pointer
14  Electron Framework!content::BrowserMainRunnerImpl::Shutdown() [browser_main_runner_impl.cc : 178 + 0x5]
    rbp = 0x00007ffee7e76280   rsp = 0x00007ffee7e76250
    rip = 0x00000001099cce74
    Found by: previous frame's frame pointer
15  Electron Framework!content::BrowserMain(content::MainFunctionParams const&) [browser_main.cc : 49 + 0x6]
    rbp = 0x00007ffee7e762d0   rsp = 0x00007ffee7e76290
    rip = 0x00000001099c8bf4
    Found by: previous frame's frame pointer
16  Electron Framework!content::ContentMainRunnerImpl::RunServiceManager(content::MainFunctionParams&, bool) [content_main_runner_impl.cc : 530 + 0x5]
    rbp = 0x00007ffee7e76350   rsp = 0x00007ffee7e762e0
    rip = 0x0000000109871f66
    Found by: previous frame's frame pointer
17  Electron Framework!content::ContentMainRunnerImpl::Run(bool) [content_main_runner_impl.cc : 879 + 0x10]
    rbp = 0x00007ffee7e763c0   rsp = 0x00007ffee7e76360
    rip = 0x0000000109871bbb
    Found by: previous frame's frame pointer
18  Electron Framework!service_manager::Main(service_manager::MainParams const&) [main.cc : 454 + 0x9]
    rbp = 0x00007ffee7e76710   rsp = 0x00007ffee7e763d0
    rip = 0x000000010bdf72c8
    Found by: previous frame's frame pointer
19  Electron Framework!content::ContentMain(content::ContentMainParams const&) [content_main.cc : 19 + 0x8]
    rbp = 0x00007ffee7e767a0   rsp = 0x00007ffee7e76720
    rip = 0x0000000108af0d54
    Found by: previous frame's frame pointer
20  Electron Framework!ElectronMain [electron_library_main.mm : 23 + 0x5]
    rbp = 0x00007ffee7e76830   rsp = 0x00007ffee7e767b0
    rip = 0x0000000107dc0bd4
    Found by: previous frame's frame pointer
21  Electron!main [electron_main.cc : 274 + 0xa]
    rbp = 0x00007ffee7e768e0   rsp = 0x00007ffee7e76840
    rip = 0x0000000107d8a110
    Found by: previous frame's frame pointer
22  libdyld.dylib!start + 0x1
    rbp = 0x00007ffee7e768f8   rsp = 0x00007ffee7e768f0
    rip = 0x00007fff70795cc9
    Found by: previous frame's frame pointer
23  libdyld.dylib!start + 0x1
    rbp = 0x00007ffee7e768f8   rsp = 0x00007ffee7e768f8
    rip = 0x00007fff70795cc9
    Found by: stack scanning

@pamtbaau
Copy link

@MatteoMeil, Do you perhaps have a minimal test project I can download?

I cannot get my Angular/Electron/Sqlite app to work, unless when using app.allowRendererProcessReuse = false.

Also, does reloading you app work consistently? My app may work 5-10 times and then fail over and over again. After a rebuild, it might not work at all.

@itsUndefined
Copy link

My app crashes when reloading even when using sqlite3@5.0.2 if I don't set app.allowRendererProcessReuse = false. Electron version is 11.3.0. For sure this is not fixed.

@itsUndefined
Copy link

Nevermind. The issue has to do with the rollback of n-api 6. Version 5.0.1 works fine.

@kewde
Copy link
Collaborator

kewde commented Mar 9, 2021

I'm sorry for the issues, I will look at re-enabling N-API 6 as soon as possible.

@kewde kewde added this to the 5.0.3 milestone Mar 9, 2021
@kewde kewde added the bug label Mar 9, 2021
@ddcado
Copy link

ddcado commented May 19, 2021

Hi,
I had the same bug, I m learning Node JS, electron, I wanted to do an app just to learn,
I read a lot of things, and I think there is two way:

  • If you use the renderer to connect your databas, you need to open a new window wich you will close and open a new one etc..., there is no crash then... You crash only if you reload your BrowserWindow nearly after the first use....
  • If You use the main process to connect to your DB, there is no crash if you have rebuild sqlite3

In both case, you need to use IpcMain / ipcRenderer...
I tried both and I had no crash then...
I hope someone will find the BUG with sqlite and the renderer.
Good luck and good job.
Edit: seems to be a security reason on chrome

@pdesantis
Copy link
Contributor

@kewde thanks for looking into this! Do you by any chance have a sense on if this will ship in the next month? No worries if not, I'm just trying to decide whether or not I should invest in a short-term fix in my app if the package will be updated soon.

@bojanbizjak
Copy link

Same issue (app crashes on reload):

electron: 14.0.0
sqlite3: 5.0.2
websql: 2.0.3

We use sqlite3 in renderer process.

It's working (app reloads) on electron: 13.3.0 with app.allowRendererProcessReuse = false

@dominic-simplan
Copy link
Author

Electron 14 removed the app.allowRendererProcessReuse option.

@sarahmolinerroy
Copy link

@kewde I see you tagged this issue for the next patch version 5.0.3. Is it possible to know the expected release date for this? It is preventing us from upgrading to Electron 14 and up. Happy to help test if we can. Thanks for looking into this!

@jbcullis
Copy link

jbcullis commented Nov 15, 2021

@kewde Same issue here.
electron 15.3.1
sqlite3: 5.0.2

Resolved by downgrading to electron 13.3 and setting allowRendererProcessReuse to false.

@daniellockyer
Copy link
Member

Would you be able to try with v5.0.3 please? 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests