Repository navigation
Description
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for a bug report that matches the one I want to file, without success.
Electron Version
18.0.0
What operating system are you using?
Windows
Operating System Version
Windows 10 Pro 19044.1645
What arch are you using?
x64
Last Known Working Electron version
16.2.3
Expected Behavior
Assuming the N-API module is correctly implemented in context-aware matter the render process does not crash.
Actual Behavior
Crash log observed in the console:
C:\Windows\system32\cmd.exe [39088]: ../../third_party/electron_node/src/api/callback.cc:68: Assertion `(Environment::GetCurrent(isolate)) == (env)' failed.
1: 00007FF7DD474AA6 node::Buffer::New+50438
2: 00007FF7DD4747E9 node::Buffer::New+49737
3: 00007FF7DD416A01 node::CallbackScope::CallbackScope+593
4: 00007FF7DD4167ED node::CallbackScope::CallbackScope+61
5: 00007FF7DE02CDB9 node::AsyncResource::CallbackScope::CallbackScope+89
6: 00007FF7DD9D5DDC node_api_get_module_file_name+4092
7: 00007FF7DD48802C uv_run+492
8: 00007FF7DBB8DFB8 node::FreeArrayBufferAllocator+23608
9: 00007FF7DEFA11E8 cppgc::internal::WriteBarrier::DijkstraMarkingBarrierRangeSlow+3187976
10: 00007FF7DF06A492 Cr_z_crc32+629122
11: 00007FF7DD4A30E2 uv_sleep+93074
12: 00007FF7DD4ACBEA uv_sleep+132762
13: 00007FF7DCEE2C45 uv_timer_get_repeat+6778117
14: 00007FF7DD34F202 IsSandboxedProcess+3875010
15: 00007FF7DBC87ECC v8::metrics::LongTaskStats::LongTaskStats+496028
16: 00007FF7DBC889AD v8::metrics::LongTaskStats::LongTaskStats+498813
17: 00007FF7DBC84F3C v8::metrics::LongTaskStats::LongTaskStats+483852
18: 00007FF7DBC852B0 v8::metrics::LongTaskStats::LongTaskStats+484736
19: 00007FF7DBA27F1D std::__1::__vector_base<v8::CpuProfileDeoptFrame,std::__1::allocator<v8::CpuProfileDeoptFrame>>::__vector_base<v8::CpuProfileDeoptFrame,std::__1::allocator<v8::CpuProfileDeoptFrame> >+46541
20: 00007FF7DF3BD8A2 Cr_z_crc32+4115858
21: 00007FF96F727034 BaseThreadInitThunk+20
22: 00007FF96F8C2651 RtlUserThreadStart+33
Testcase Gist URL
No response
Additional Information
I have created a separate reproduction repo with N-API module and a small electron application:
https://github.com/martinzak-zaber/electron-crash-repro
Preconditions
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
Basic Repro
The crash can only be observed in a child window that is opened using window.open function on the same domain and loads the same native module. The app crashes after a native module calls BlockingCall on ThreadSafeFunction created using child's Napi::Env. From all my understanding the native module is context-aware and works properly with Napi::Env. Sync calls do not seem to be affected.
Workaround
We have come up with two workarounds. The first is to set nativeWindowOpen to false. This is only possible on electron < 18. The second is to return deny in setWindowOpenHandler and still open the window manually using the provided URL. This works universally.
Notes
The crash does not occur if all the native work is done in preload script (as is perhaps for a lot of applications). The preload script is run only once in that scenario.
I am not 100% confident that this is a bug. I don't have a deep understanding of how v8 isolate and node_env should work in parent-child windows. Perhaps the native module is not correctly implemented.
You may wonder why we use nodeIntegration and contextIsolation.
It's because our application is strictly desktop and only loads local assets. Using our native node.js library directly makes our development rather convenient.
Thank you, the electron team, and all the contributors for maintaining the amazing ecosystem.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsUnsorted Items
- StatusShow more project fields👍 Does Not Block Stable
Activity
gpetrov commentedon Aug 24, 2022
Any news on this @codebytere ? We are facing the same issue when using some native modules in native popup windows.
gpetrov commentedon Aug 24, 2022
Disabling the native windows doesn't help with us. Running on Windows 10 with Electron 18.3.9
The crash we got is:
martinzak-zaber commentedon Aug 24, 2022
The nativeWindowOpen workaround only works for
Electron < 18(see description). The denying of the window open is what we currently use on Electron 18.github-actions commentedon Nov 23, 2022
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!
nekename commentedon Jan 7, 2023
bump. not stale.
lorand-horvath commentedon Feb 3, 2023
It looks like this bug has been biting VSCode for some time now (Windows 7, 10 and Linux). My report is here microsoft/vscode#130320 (comment)
and still seeing it with latest VSCode 1.75.0
david-metrica commentedon May 1, 2023
I can confirm this is still happening in Electron 19. It also happens on MacOS.
I am running electron with golden layout and a native module that's supposedly context-aware.
Whenever a thread-safe function is called in a new window it crashes:
../../third_party/electron_node/src/api/callback.cc:74:node::InternalCallbackScope::InternalCallbackScope(node::Environment *, Local<v8::Object>, const node::async_context &, int): Assertion (Environment::GetCurrent(isolate)) == (env) failed.I have this on my setup.ts
@gpetrov @ninjadev64 Were you able to fix this?
gpetrov commentedon Jun 11, 2023
this seems to be related to the parent window passed on overrideBrowserWindowOptions @codebytere
When specified a crash occurs on MacOS, like:
Details
``` 2023-06-11 19:25:23.669 Electron[55553:6300949] -[NSTaggedPointerString parentWindow]: unrecognized selector sent to instance 0xb840f1c0f85f83ae 2023-06-11 19:25:23.671 Electron[55553:6300949] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSTaggedPointerString parentWindow]: unrecognized selector sent to instance 0xb840f1c0f85f83ae' *** First throw call stack: ( 0 CoreFoundation 0x00000001ad11c3e8 __exceptionPreprocess + 176 1 libobjc.A.dylib 0x00000001acc66ea8 objc_exception_throw + 60 2 CoreFoundation 0x00000001ad1bec0c -[NSObject(NSObject) __retain_OA] + 0 3 CoreFoundation 0x00000001ad082660 ___forwarding___ + 1600 4 CoreFoundation 0x00000001ad081f60 _CF_forwarding_prep_0 + 96 5 Electron Framework 0x000000010a979870 _ZN4node24FreeArrayBufferAllocatorEPNS_20ArrayBufferAllocatorE + 267920 6 Electron Framework 0x000000010a978f10 _ZN4node24FreeArrayBufferAllocatorEPNS_20ArrayBufferAllocatorE + 265520 7 Electron Framework 0x000000010a8c547c _ZN2v89CodeEvent10GetCommentEv + 4068 8 Electron Framework 0x000000010a7f96d4 _ZNK2v88internal20CodeCommentsIterator4sizeEv + 56264 9 Electron Framework 0x000000010a7fa9f8 _ZNK2v88internal20CodeCommentsIterator4sizeEv + 61164 10 Electron Framework 0x000000010a7fb0f0 _ZNK2v88internal20CodeCommentsIterator4sizeEv + 62948 11 Electron Framework 0x000000010a7ef9c8 _ZNK2v88internal20CodeCommentsIterator4sizeEv + 16060 12 Electron Framework 0x000000010a7ef8c4 _ZNK2v88internal20CodeCommentsIterator4sizeEv + 15800 13 Electron Framework 0x000000010b709fbc _ZN2v88internal9Accessors12MakeAccessorEPNS0_7IsolateENS0_6HandleINS0_4NameEEEPFvNS_5LocalINS_4NameEEERKNS_20PropertyCallbackInfoINS_5ValueEEEEPFvS9_NS7_ISB_EERKNSA_INS_7BooleanEEEE + 15500 14 Electron Framework 0x000000010b709b90 _ZN2v88internal9Accessors12MakeAccessorEPNS0_7IsolateENS0_6HandleINS0_4NameEEEPFvNS_5LocalINS_4NameEEERKNS_20PropertyCallbackInfoINS_5ValueEEEEPFvS9_NS7_ISB_EERKNSA_INS_7BooleanEEEE + 14432 15 Electron Framework 0x000000010b70907c _ZN2v88internal9Accessors12MakeAccessorEPNS0_7IsolateENS0_6HandleINS0_4NameEEEPFvNS_5LocalINS_4NameEEERKNS_20PropertyCallbackInfoINS_5ValueEEEEPFvS9_NS7_ISB_EERKNSA_INS_7BooleanEEEE + 11596 16 ??? 0x0000000157edb518 0x0 + 5770163480 17 ??? 0x0000000157e49f08 0x0 + 5769568008 18 ??? 0x0000000157f98d38 0x0 + 5770939704 19 ??? 0x0000000157e4ccfc 0x0 + 5769579772 20 ??? 0x0000000157e4ccfc 0x0 + 5769579772 21 ??? 0x00000001503ec984 0x0 + 5641259396 22 ??? 0x00000001503b6ce8 0x0 + 5641039080 23 ??? 0x00000001504cbcec 0x0 + 5642173676 24 ??? 0x0000000157e4ab48 0x0 + 5769571144 25 ??? 0x0000000157e4a838 0x0 + 5769570360 26 Electron Framework 0x000000010b7c5014 _ZN2v88internal9Execution4CallEPNS0_7IsolateENS0_6HandleINS0_6ObjectEEES6_iPS6_ + 452 27 Electron Framework 0x000000010b6b8dcc _ZN2v88Function4CallENS_5LocalINS_7ContextEEENS1_INS_5ValueEEEiPS5_ + 516 28 Electron Framework 0x0000000110a78c8c _ZN4node13CallbackScopeD1Ev + 1744 29 Electron Framework 0x0000000110a78ff4 _ZN4node12MakeCallbackEPN2v87IsolateENS0_5LocalINS0_6ObjectEEENS3_INS0_8FunctionEEEiPNS3_INS0_5ValueEEENS_13async_contextE + 256 30 Electron Framework 0x000000010a937174 _ZN2v89CodeEvent13GetScriptNameEv + 189132 31 Electron Framework 0x000000010a8793e4 _ZN2v815ValueSerializer8Delegate23GetWasmModuleTransferIdEPNS_7IsolateENS_5LocalINS_16WasmModuleObjectEEE + 103540 32 Electron Framework 0x000000010a86039c _ZN2v815ValueSerializer8Delegate23GetWasmModuleTransferIdEPNS_7IsolateENS_5LocalINS_16WasmModuleObjectEEE + 1068 33 Electron Framework 0x000000010a86008c _ZN2v815ValueSerializer8Delegate23GetWasmModuleTransferIdEPNS_7IsolateENS_5LocalINS_16WasmModuleObjectEEE + 284 34 Electron Framework 0x000000010cc749f4 _ZN2v88internal20SetupIsolateDelegate13SetupBuiltinsEPNS0_7IsolateEb + 8792828 35 Electron Framework 0x000000010cb2eff4 _ZN2v88internal20SetupIsolateDelegate13SetupBuiltinsEPNS0_7IsolateEb + 7459068 36 Electron Framework 0x000000010b4e0b94 _ZN4node25GetEnvironmentIsolateDataEPNS_11EnvironmentE + 477436 37 Electron Framework 0x000000010cb4d324 _ZN2v88internal20SetupIsolateDelegate13SetupBuiltinsEPNS0_7IsolateEb + 7582764 38 Electron Framework 0x000000010d79c770 _ZN4node23GetMultiIsolatePlatformEPNS_11IsolateDataE + 11692968 39 Electron Framework 0x000000010d7a10d4 _ZN4node23GetMultiIsolatePlatformEPNS_11IsolateDataE + 11711756 40 Electron Framework 0x000000010d79e580 _ZN4node23GetMultiIsolatePlatformEPNS_11IsolateDataE + 11700664 41 Electron Framework 0x000000010da83058 _ZN4node23GetMultiIsolatePlatformEPNS_11IsolateDataE + 14734480 42 Electron Framework 0x000000010d4b71c4 _ZN4node23GetMultiIsolatePlatformEPNS_11IsolateDataE + 8656380 43 Electron Framework 0x000000010d4d14f0 _ZN4node23GetMultiIsolatePlatformEPNS_11IsolateDataE + 8763688 44 Electron Framework 0x000000010d51f1b0 _ZN4node23GetMultiIsolatePlatformEPNS_11IsolateDataE + 9082344 45 Electron Framework 0x000000010a73c010 Electron Framework + 1720336 46 Electron Framework 0x000000010d51e8f8 _ZN4node23GetMultiIsolatePlatformEPNS_11IsolateDataE + 9080112 47 CoreFoundation 0x00000001ad0a1a08 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 48 CoreFoundation 0x00000001ad0a199c __CFRunLoopDoSource0 + 176 49 CoreFoundation 0x00000001ad0a170c __CFRunLoopDoSources0 + 244 50 CoreFoundation 0x00000001ad0a0310 __CFRunLoopRun + 836 51 CoreFoundation 0x00000001ad09f878 CFRunLoopRunSpecific + 612 52 HIToolbox 0x00000001b677ffa0 RunCurrentEventLoopInMode + 292 53 HIToolbox 0x00000001b677fde4 ReceiveNextEventCommon + 672 54 HIToolbox 0x00000001b677fb2c _BlockUntilNextEventMatchingListInModeWithFilter + 72 55 AppKit 0x00000001b0325838 _DPSNextEvent + 632 56 AppKit 0x00000001b03249c8 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 728 57 AppKit 0x00000001b0318df8 -[NSApplication run] + 464 58 Electron Framework 0x000000010d51fd80 _ZN4node23GetMultiIsolatePlatformEPNS_11IsolateDataE + 9085368 59 Electron Framework 0x000000010d51e478 _ZN4node23GetMultiIsolatePlatformEPNS_11IsolateDataE + 9078960 60 Electron Framework 0x000000010d4d2050 _ZN4node23GetMultiIsolatePlatformEPNS_11IsolateDataE + 8766600 61 Electron Framework 0x000000010d49c4dc _ZN4node23GetMultiIsolatePlatformEPNS_11IsolateDataE + 8546580 62 Electron Framework 0x000000010c78dfd0 _ZN2v88internal20SetupIsolateDelegate13SetupBuiltinsEPNS0_7IsolateEb + 3653848 63 Electron Framework 0x000000010c78f8e4 _ZN2v88internal20SetupIsolateDelegate13SetupBuiltinsEPNS0_7IsolateEb + 3660268 64 Electron Framework 0x000000010c78bc5c _ZN2v88internal20SetupIsolateDelegate13SetupBuiltinsEPNS0_7IsolateEb + 3644772 65 Electron Framework 0x000000010aa99608 _ZN2v88internal8compiler10BasicBlock15set_loop_headerEPS2_ + 13524 66 Electron Framework 0x000000010aa9a514 _ZN2v88internal8compiler10BasicBlock15set_loop_headerEPS2_ + 17376 67 Electron Framework 0x000000010aa9a364 _ZN2v88internal8compiler10BasicBlock15set_loop_headerEPS2_ + 16944 68 Electron Framework 0x000000010aa98e28 _ZN2v88internal8compiler10BasicBlock15set_loop_headerEPS2_ + 11508 69 Electron Framework 0x000000010aa99054 _ZN2v88internal8compiler10BasicBlock15set_loop_headerEPS2_ + 12064 70 Electron Framework 0x000000010a7c91d8 ElectronMain + 128 71 dyld 0x00000001acc97e50 start + 2544 ) ```When parent is omitted that no crash occurs.
3 remaining items
alissawix commentedon Dec 16, 2023
I'm having a very similar issue with an iframe
the error I get is the same :
electron_node\src\api\callback.cc:74: Assertion '(Environment::GetCurrent(isolate)) == (env)' failed.is there a workaround?
LittoCats commentedon Jan 10, 2024
Same issue for my app.
oalfroukh commentedon Mar 26, 2024
Hi @codebytere
window.openand theoverrideBrowserWindowOptionshas these valuescontextIsolation: false and nodeIntegration: false,on electronv28.2.5and that Child window doesn't use any native modules!!webPreferences: {contextIsolation: false,nodeIntegration: false,sandbox: false,test: cover napi thread-safe functions in child window environments
fix: illegal access errors when a same-process child window or subfra…
fix: illegal access errors when a same-process child window or subfra…
fix: illegal access errors when a same-process child window or subfra…
fix: illegal access errors when a same-process child window or subfra…
fix: illegal access errors when a same-process child window or subfra…