electron app 在macbook pro 2017 上运行频繁闪退


#1

最近在开发一个基于electron的单页应用时遇到个头疼问题,想请教各位高手帮忙支支招。(技术选型是electron + webpack)

问题是这样的,每当打开并运行这个app后,当我的输入法调成系统自带的简体拼音,并用鼠标点击页面上某个input元素或textarea元素或某个可点击元素时(如设置了cursor:pointer的div元素),app会闪退。

此时查看ide控制台的报错信息会发现如下信息:

Electron(9467,0x7fffeed5c3c0) malloc: *** mach_vm_map(size=18446744073709543424) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
[9467:1110/153317.794039:FATAL:memory.cc(22)] Out of memory. size=0
0   Electron Framework                  0x0000000105069b2c crashpad::CloseMultipleNowOrOnExec(int, int) + 933804
1   Electron Framework                  0x0000000105034223 crashpad::CloseMultipleNowOrOnExec(int, int) + 714403
2   Electron Framework                  0x00000001050388f3 crashpad::CloseMultipleNowOrOnExec(int, int) + 732531
3   Electron Framework                  0x0000000104ff8cda crashpad::CloseMultipleNowOrOnExec(int, int) + 471386
4   libsystem_malloc.dylib              0x00007fffe5fc1282 malloc_zone_malloc + 107
5   libsystem_malloc.dylib              0x00007fffe5fc0200 malloc + 24
6   HIToolbox                           0x00007fffcfe7d8bb -[IMKInputSession _coreAttributesFromRange:whichAttributes:completionHandler:] + 61
7   HIToolbox                           0x00007fffcfe7f939 -[IMKInputSession attributedSubstringFromRange:completionHandler:] + 186
8   HIToolbox                           0x00007fffcfe6f137 __61-[IMKInputSession imkxpc_attributedSubstringFromRange:reply:]_block_invoke + 530
9   CoreFoundation                      0x00007fffd06d917c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
10  CoreFoundation                      0x00007fffd06b9f84 __CFRunLoopDoBlocks + 356
11  CoreFoundation                      0x00007fffd06b9ac6 __CFRunLoopRun + 1878
12  CoreFoundation                      0x00007fffd06b9114 CFRunLoopRunSpecific + 420
13  HIToolbox                           0x00007fffcfe5619e -[IMKInputSessionXPCInvocation invocationAwaitXPCReply] + 606
14  HIToolbox                           0x00007fffcfe58750 -[IMKInputSession activate] + 3471
15  HIToolbox                           0x00007fffcfe0c7ab IMKInputSessionActivate + 36
16  HIToolbox                           0x00007fffcfe0bb3c ActivateInputMethodInstance + 100
17  HIToolbox                           0x00007fffcfdffbcc utActivateInputMethod + 45
18  HIToolbox                           0x00007fffcfdff735 utActivateIM4Document + 72
19  HIToolbox                           0x00007fffcfdff5ad utOpenActivateThisDocsInputMethod + 125
20  HIToolbox                           0x00007fffcfc2de09 MyActivateTSMDocument + 1687
21  AppKit                              0x00007fffce2f488d -[NSTextInputContext activate] + 284
22  AppKit                              0x00007fffceb85ec2 +[NSTextInputContext currentInputContext_withFirstResponderSync:] + 362
23  AppKit                              0x00007fffce1b2e42 -[NSApplication updateWindows] + 96
24  Electron Framework                  0x000000010553d40f crashpad::CloseMultipleNowOrOnExec(int, int) + 5994639
25  Electron Framework                  0x000000010564aa96 crashpad::CloseMultipleNowOrOnExec(int, int) + 7098134
26  Electron Framework                  0x000000010564a726 crashpad::CloseMultipleNowOrOnExec(int, int) + 7097254
27  Electron Framework                  0x000000010552607b crashpad::CloseMultipleNowOrOnExec(int, int) + 5899515
28  Electron Framework                  0x0000000105522f1f crashpad::CloseMultipleNowOrOnExec(int, int) + 5886879
29  Electron Framework                  0x0000000105bd511b crashpad::CloseMultipleNowOrOnExec(int, int) + 12907931
30  Electron Framework                  0x000000010507a5c0 crashpad::CloseMultipleNowOrOnExec(int, int) + 1002048
31  Electron Framework                  0x0000000105043c5b crashpad::CloseMultipleNowOrOnExec(int, int) + 778459
32  Electron Framework                  0x0000000105043fac crashpad::CloseMultipleNowOrOnExec(int, int) + 779308
33  Electron Framework                  0x0000000105044373 crashpad::CloseMultipleNowOrOnExec(int, int) + 780275
34  Electron Framework                  0x00000001050477fa crashpad::CloseMultipleNowOrOnExec(int, int) + 793722
35  Electron Framework                  0x0000000104ffbd5a crashpad::CloseMultipleNowOrOnExec(int, int) + 483802
36  Electron Framework                  0x0000000105047224 crashpad::CloseMultipleNowOrOnExec(int, int) + 792228
37  CoreFoundation                      0x00007fffd06d9321 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
38  CoreFoundation                      0x00007fffd06ba21d __CFRunLoopDoSources0 + 557
39  CoreFoundation                      0x00007fffd06b9716 __CFRunLoopRun + 934
40  CoreFoundation                      0x00007fffd06b9114 CFRunLoopRunSpecific + 420
41  HIToolbox                           0x00007fffcfc19ebc RunCurrentEventLoopInMode + 240
42  HIToolbox                           0x00007fffcfc19cf1 ReceiveNextEventCommon + 432
43  HIToolbox                           0x00007fffcfc19b26 _BlockUntilNextEventMatchingListInModeWithFilter + 71
44  AppKit                              0x00007fffce1b0a54 _DPSNextEvent + 1120
45  AppKit                              0x00007fffce92c7ee -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2796
46  AppKit                              0x00007fffce1a53db -[NSApplication run] + 926
47  Electron Framework                  0x000000010504806e crashpad::CloseMultipleNowOrOnExec(int, int) + 795886
48  Electron Framework                  0x000000010504765c crashpad::CloseMultipleNowOrOnExec(int, int) + 793308
49  Electron Framework                  0x000000010504392e crashpad::CloseMultipleNowOrOnExec(int, int) + 777646
50  Electron Framework                  0x000000010505c983 crashpad::CloseMultipleNowOrOnExec(int, int) + 880131
51  Electron Framework                  0x00000001052beafb crashpad::CloseMultipleNowOrOnExec(int, int) + 3379067
52  Electron Framework                  0x00000001052be950 crashpad::CloseMultipleNowOrOnExec(int, int) + 3378640
53  Electron Framework                  0x00000001052c1a72 crashpad::CloseMultipleNowOrOnExec(int, int) + 3391218
54  Electron Framework                  0x00000001052ba53c crashpad::CloseMultipleNowOrOnExec(int, int) + 3361212
55  Electron Framework                  0x0000000105213470 crashpad::CloseMultipleNowOrOnExec(int, int) + 2676976
56  Electron Framework                  0x00000001052125c6 crashpad::CloseMultipleNowOrOnExec(int, int) + 2673222
57  Electron Framework                  0x0000000104df3447 AtomMain + 71
58  Electron                            0x00000001040c9f26 main + 38
59  libdyld.dylib                       0x00007fffe5e3f235 start + 1

此时查看系统生成的问题报告时则显示如下信息

Process:               Electron [9581]
Path:                  /Users/USER/*/Electron.app/Contents/MacOS/Electron
Identifier:            com.github.electron
Version:               1.7.9 (1.7.9)
Code Type:             X86-64 (Native)
Parent Process:        node [9577]
Responsible:           Electron [564]
User ID:               501

Date/Time:             2017-11-10 15:46:19.698 +0800
OS Version:            Mac OS X 10.12.6 (16G1036)
Report Version:        12
Anonymous UUID:        1C11A4C0-BAE5-E9A9-092C-C2BDDC5C8921

Sleep/Wake UUID:       20776B80-6353-4746-B5E2-734D1109510D

Time Awake Since Boot: 35000 seconds
Time Since Wake:       9600 seconds

System Integrity Protection: enabled

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

Exception Type:        EXC_BREAKPOINT (SIGTRAP)
Exception Codes:       0x0000000000000002, 0x0000000000000000

Thread 0 Crashed:: CrBrowserMain  Dispatch queue: com.apple.main-thread
0   com.github.electron.framework 	0x000000010e1dee51 0x10dfcf000 + 2162257
1   com.github.electron.framework 	0x000000010e21284c 0x10dfcf000 + 2373708
2   com.github.electron.framework 	0x000000010e2168f3 0x10dfcf000 + 2390259
3   com.github.electron.framework 	0x000000010e1d6cda 0x10dfcf000 + 2129114
4   libsystem_malloc.dylib        	0x00007fffe5fc1282 malloc_zone_malloc + 107
5   libsystem_malloc.dylib        	0x00007fffe5fc0200 malloc + 24
6   com.apple.HIToolbox           	0x00007fffcfe7d8bb -[IMKInputSession _coreAttributesFromRange:whichAttributes:completionHandler:] + 61
7   com.apple.HIToolbox           	0x00007fffcfe7f939 -[IMKInputSession attributedSubstringFromRange:completionHandler:] + 186
8   com.apple.HIToolbox           	0x00007fffcfe6f137 __61-[IMKInputSession imkxpc_attributedSubstringFromRange:reply:]_block_invoke + 530
9   com.apple.CoreFoundation      	0x00007fffd06d917c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
10  com.apple.CoreFoundation      	0x00007fffd06b9f84 __CFRunLoopDoBlocks + 356
11  com.apple.CoreFoundation      	0x00007fffd06b9ac6 __CFRunLoopRun + 1878
12  com.apple.CoreFoundation      	0x00007fffd06b9114 CFRunLoopRunSpecific + 420
13  com.apple.HIToolbox           	0x00007fffcfe5619e -[IMKInputSessionXPCInvocation invocationAwaitXPCReply] + 606
14  com.apple.HIToolbox           	0x00007fffcfe58750 -[IMKInputSession activate] + 3471
15  com.apple.HIToolbox           	0x00007fffcfe0c7ab IMKInputSessionActivate + 36
16  com.apple.HIToolbox           	0x00007fffcfe0bb3c ActivateInputMethodInstance + 100
17  com.apple.HIToolbox           	0x00007fffcfdffbcc utActivateInputMethod + 45
18  com.apple.HIToolbox           	0x00007fffcfdff735 utActivateIM4Document + 72
19  com.apple.HIToolbox           	0x00007fffcfdff5ad utOpenActivateThisDocsInputMethod + 125
20  com.apple.HIToolbox           	0x00007fffcfc2de09 MyActivateTSMDocument + 1687
21  com.apple.AppKit              	0x00007fffce2f488d -[NSTextInputContext activate] + 284
22  com.apple.AppKit              	0x00007fffceb85ec2 +[NSTextInputContext currentInputContext_withFirstResponderSync:] + 362
23  com.apple.AppKit              	0x00007fffce1b2e42 -[NSApplication updateWindows] + 96
24  com.github.electron.framework 	0x000000010e71b40f 0x10dfcf000 + 7652367
25  com.github.electron.framework 	0x000000010e828a96 0x10dfcf000 + 8755862
26  com.github.electron.framework 	0x000000010e828726 0x10dfcf000 + 8754982
27  com.github.electron.framework 	0x000000010e70407b 0x10dfcf000 + 7557243
28  com.github.electron.framework 	0x000000010e700f1f 0x10dfcf000 + 7544607
29  com.github.electron.framework 	0x000000010edb311b 0x10dfcf000 + 14565659
30  com.github.electron.framework 	0x000000010e2585c0 0x10dfcf000 + 2659776
31  com.github.electron.framework 	0x000000010e221c5b 0x10dfcf000 + 2436187
32  com.github.electron.framework 	0x000000010e221fac 0x10dfcf000 + 2437036
33  com.github.electron.framework 	0x000000010e222373 0x10dfcf000 + 2438003
34  com.github.electron.framework 	0x000000010e2257fa 0x10dfcf000 + 2451450
35  com.github.electron.framework 	0x000000010e1d9d5a 0x10dfcf000 + 2141530
36  com.github.electron.framework 	0x000000010e225224 0x10dfcf000 + 2449956
37  com.apple.CoreFoundation      	0x00007fffd06d9321 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
38  com.apple.CoreFoundation      	0x00007fffd06ba21d __CFRunLoopDoSources0 + 557
39  com.apple.CoreFoundation      	0x00007fffd06b9716 __CFRunLoopRun + 934
40  com.apple.CoreFoundation      	0x00007fffd06b9114 CFRunLoopRunSpecific + 420
41  com.apple.HIToolbox           	0x00007fffcfc19ebc RunCurrentEventLoopInMode + 240
42  com.apple.HIToolbox           	0x00007fffcfc19cf1 ReceiveNextEventCommon + 432
43  com.apple.HIToolbox           	0x00007fffcfc19b26 _BlockUntilNextEventMatchingListInModeWithFilter + 71
44  com.apple.AppKit              	0x00007fffce1b0a54 _DPSNextEvent + 1120
45  com.apple.AppKit              	0x00007fffce92c7ee -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2796
46  com.apple.AppKit              	0x00007fffce1a53db -[NSApplication run] + 926
47  com.github.electron.framework 	0x000000010e22606e 0x10dfcf000 + 2453614
48  com.github.electron.framework 	0x000000010e22565c 0x10dfcf000 + 2451036
49  com.github.electron.framework 	0x000000010e22192e 0x10dfcf000 + 2435374
50  com.github.electron.framework 	0x000000010e23a983 0x10dfcf000 + 2537859
51  com.github.electron.framework 	0x000000010e49cafb 0x10dfcf000 + 5036795
52  com.github.electron.framework 	0x000000010e49c950 0x10dfcf000 + 5036368
53  com.github.electron.framework 	0x000000010e49fa72 0x10dfcf000 + 5048946
54  com.github.electron.framework 	0x000000010e49853c 0x10dfcf000 + 5018940
55  com.github.electron.framework 	0x000000010e3f1470 0x10dfcf000 + 4334704
56  com.github.electron.framework 	0x000000010e3f05c6 0x10dfcf000 + 4330950
57  com.github.electron.framework 	0x000000010dfd1447 AtomMain + 71
58  com.github.electron           	0x000000010dd12f26 main + 38
59  libdyld.dylib                 	0x00007fffe5e3f235 start + 1

Thread 1:: NetworkConfigWatcher

 ... ...

Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x0000000000000400  rbx: 0x0000000000000000  rcx: 0x0000000000000010  rdx: 0xfffffffffffffff0
  rdi: 0x000000011222f7a4  rsi: 0x00007fdb0c18add0  rbp: 0x00007fff51ee76e0  rsp: 0x00007fff51ee76e0
   r8: 0x0000000000000040   r9: 0x00007fffeed40040  r10: 0x000000010df83110  r11: 0x0000002445d5cd10
  r12: 0x00007fff51ee7710  r13: 0x00007fff51ee7bf8  r14: 0x00007fff51ee7be8  r15: 0x00007fff51ee7bf0
  rip: 0x000000010e1dee51  rfl: 0x0000000000000246  cr2: 0x000004c362907000
  
Logical CPU:     0
Error Code:      0x00000000
Trap Number:     3


Binary Images:
       0x10dd12000 -        0x10dd12ff7 +com.github.electron (1.7.9 - 1.7.9) <CB63147A-C9DC-308B-8CA1-EE92A5042E8E> /Users/USER/*/Electron.app/Contents/MacOS/Electron
       0x10dd15000 -        0x10dd2ffff +com.github.Squirrel (1.0 - 1) <0A9F60FF-F2D2-364A-962A-65137E68760E> /Users/USER/*/Electron.app/Contents/Frameworks/Squirrel.framework/Versions/A/Squirrel
       0x10dd51000 -        0x10ddb4ff7 +org.reactivecocoa.ReactiveCocoa (1.0 - 1) <701B20DE-3ADD-3643-B52A-E05744C30DB3> /Users/USER/*/Electron.app/Contents/Frameworks/ReactiveCocoa.framework/Versions/A/ReactiveCocoa
       0x10de26000 -        0x10de3afff +org.mantle.Mantle (1.0 - ???) <31915DD6-48E6-3706-A076-C9D4CE17F4F6> /Users/USER/*/Electron.app/Contents/Frameworks/Mantle.framework/Versions/A/Mantle
       0x10de4c000 -        0x10de8aff7  com.apple.audio.midi.CoreMIDI (1.10 - 88) <5E2D1F53-B466-312E-AEA7-117B68C9A7F0> /System/Library/Frameworks/CoreMIDI.framework/Versions/A/CoreMIDI
       0x10deb2000 -        0x10decbfff  libexpat.1.dylib (15.1) <588CA992-60BB-363B-BEE7-3CC0A26C1AFA> /usr/lib/libexpat.1.dylib
       0x10df08000 -        0x10df17ffb  libSimplifiedChineseConverter.dylib (70) <9DF419B1-9049-3FB1-B6BB-85267B8E3B06> /System/Library/CoreServices/Encodings/libSimplifiedChineseConverter.dylib
       0x10df44000 -        0x10df81dc7  dyld (433.5) <93EA668C-4BB2-3646-96E9-B406B81308D6> /usr/lib/dyld
       0x10dfcf000 -        0x111f34f53 +com.github.electron.framework (0) <077F6FDF-9D71-317F-B1F2-1E49A6846EA3> /Users/USER/*/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework
       0x11248a000 -        0x11339cfff +libnode.dylib (0) <E190A1BE-9E30-37BC-B707-3516EF6CD32C> /Users/USER/*/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libnode.dylib
       0x11362d000 -        0x113891fef +libffmpeg.dylib (0) <C6D0AEFA-0122-35FA-8EDE-369DCD7E9304> /Use

… …

External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 1
    thread_create: 0
    thread_set_state: 0
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 24846
    thread_create: 0
    thread_set_state: 0

VM Region Summary:
ReadOnly portion of Libraries: Total=403.7M resident=0K(0%) swapped_out_or_unallocated=403.7M(100%)
Writable regions: Total=458.8M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=458.8M(100%)
 
                                VIRTUAL   REGION 
REGION TYPE                        SIZE    COUNT (non-coalesced) 
===========                     =======  ======= 
Accelerate framework               896K        6 
Activity Tracing                   256K        2 
CG backing stores                 24.3M        9 
CG image                           132K       12 
CoreAnimation                      508K        7 
CoreUI image data                 1248K        9 
CoreUI image file                  192K        6 
Dispatch continuations            16.0M        2 
Foundation                          28K        3 
IOKit                             19.4M       19 
Kernel Alloc Once                    8K        2 
MALLOC                           138.2M       35 
MALLOC guard page                   48K       11 
Memory Tag 242                      12K        2 
Memory Tag 255                   532.0M       68 
STACK GUARD                       56.2M       44 
Stack                            219.8M       86 
VM_ALLOCATE                         72K       11 
__DATA                            35.6M      283 
__GLSLBUILTINS                    2588K        2 
__IMAGE                            528K        2 
__LINKEDIT                       122.1M       21 
__TEXT                           281.5M      276 
__UNICODE                          556K        2 
mapped file                      154.9M       44 
shared memory                     41.0M       37 
===========                     =======  ======= 
TOTAL                              1.6G      975 

Model: MacBookPro14,3, BootROM MBP143.0167.B00, 4 processors, Intel Core i7, 2.8 GHz, 16 GB, SMC 2.45f0
Graphics: kHW_IntelHDGraphics630Item, Intel HD Graphics 630, Built-In
Graphics: kHW_AMDRadeonPro555Item, Radeon Pro 555, PCIe, 2048 MB
Memory Module: BANK 0/DIMM0, 8 GB, LPDDR3, 2133 MHz, 0x80CE, 0x4B3445424533303445422D45474347202020
Memory Module: BANK 1/DIMM0, 8 GB, LPDDR3, 2133 MHz, 0x80CE, 0x4B3445424533303445422D45474347202020
AirPort: spairport_wireless_card_type_airport_extreme (0x14E4, 0x173), Broadcom BCM43xx 1.0 (7.21.171.131.1a1)
Bluetooth: Version 5.0.5f1, 3 services, 27 devices, 1 incoming serial ports
Network Service: Wi-Fi, AirPort, en0
USB Device: USB 3.0 Bus
USB Device: USB2.0 Hub
USB Device: USB 2.0 BILLBOARD
USB Device: Dell Universal Receiver
USB Device: iBridge
USB Device: USB3.0 Hub
Thunderbolt Bus: MacBook Pro, Apple Inc., 22.2
Thunderbolt Bus: MacBook Pro, Apple Inc., 22.2

奇怪的是app唯独在新版的macbook pro2017上运行时会出现此问题,而且出现问题时貌似与输入法设置也有关系,默认输入法设置为简体拼音时点着点着就会出现这个问题,如果默认输入法设置为其他则不会。

想请教下各位高手该如何解决?谢谢!