如何修复Facebook :: react :: Value :: toJSONString中的崩溃

时间:2019-02-07 17:33:15

标签: android react-native expo sigsegv

问题

我在生产中遇到了一个令人讨厌的崩溃报告,我无法解决,但我认为它与此github issue有关。

问题在于,崩溃似乎是随机出现的,而不是在执行某些操作之后出现的。

我跟踪了下一行的source,我认为这与崩溃有关,但是我不确定。

2019-02-07 14:22:50.203 10137-10137/? A/DEBUG:     #11 pc 0005e669  /data/app/com.xyzor.timer-1/lib/arm/libjsc.so (JSValueCreateJSONString+72)

更新:
通过使用addr2line,我设法跟踪了如下堆栈:

ReactCommon/jschelpers/Value.cpp#64

2019-02-07 14:22:50.203 10137-10137/? A/DEBUG:     #11 pc 0005e669  /data/app/com.xyzor.timer-1/lib/arm/libjsc.so (JSValueCreateJSONString+72)

ReactCommon/cxxreact/MethodCall.cpp#21

2019-02-07 14:22:50.203 10137-10137/? A/DEBUG:     #12 pc 0003b3b9  /data/app/com.xyzor.timer-1/lib/arm/libreactnativejni.so (_ZNK8facebook5react5Value12toJSONStringEj+20)

ReactCommon/cxxreact/Instance.cpp#69

2019-02-07 14:22:50.203 10137-10137/? A/DEBUG:     #13 pc 00033c3b  /data/app/com.xyzor.timer-1/lib/arm/libreactnativejni.so (_ZN8facebook5react11JSCExecutor19flushQueueImmediateEONS0_5ValueE+26)

ReactCommon/cxxreact/Instance.cpp#125

2019-02-07 14:22:50.203 10137-10137/? A/DEBUG:     #14 pc 00033d6f  /data/app/com.xyzor.timer-1/lib/arm/libreactnativejni.so (_ZN8facebook5react11JSCExecutor25nativeFlushQueueImmediateEjPKPK13OpaqueJSValue+86)

更新:
我创建了一个小吃演示来重现崩溃。
通过每次"012345678".repeat(1024*1024)都存储此字符串,可以重现该错误。 (对我来说,当我添加第三个或第四个时,它会崩溃)

Snack demo

问题:

如果您有任何建议如何在崩溃发生时从adb logcat或其他软件中获取更多信息,请告诉我。

如果您之前也遇到过类似的错误,请让我知道您是如何解决的以及崩溃的原因是什么。

崩溃报告:

2019-02-07 14:22:50.203 10137-10137/? A/DEBUG:     #00 pc 003b3ac0  /data/app/com.xyzor.timer-1/lib/arm/libjsc.so
2019-02-07 14:22:50.203 10137-10137/? A/DEBUG:     #01 pc 003b1601  /data/app/com.xyzor.timer-1/lib/arm/libjsc.so
2019-02-07 14:22:50.203 10137-10137/? A/DEBUG:     #02 pc 00364861  /data/app/com.xyzor.timer-1/lib/arm/libjsc.so
2019-02-07 14:22:50.203 10137-10137/? A/DEBUG:     #03 pc 0037134d  /data/app/com.xyzor.timer-1/lib/arm/libjsc.so
2019-02-07 14:22:50.203 10137-10137/? A/DEBUG:     #04 pc 003706c1  /data/app/com.xyzor.timer-1/lib/arm/libjsc.so
2019-02-07 14:22:50.203 10137-10137/? A/DEBUG:     #05 pc 00370e55  /data/app/com.xyzor.timer-1/lib/arm/libjsc.so
2019-02-07 14:22:50.203 10137-10137/? A/DEBUG:     #06 pc 00290f71  /data/app/com.xyzor.timer-1/lib/arm/libjsc.so
2019-02-07 14:22:50.203 10137-10137/? A/DEBUG:     #07 pc 00291fbd  /data/app/com.xyzor.timer-1/lib/arm/libjsc.so
2019-02-07 14:22:50.203 10137-10137/? A/DEBUG:     #08 pc 002913ab  /data/app/com.xyzor.timer-1/lib/arm/libjsc.so
2019-02-07 14:22:50.203 10137-10137/? A/DEBUG:     #09 pc 002908d9  /data/app/com.xyzor.timer-1/lib/arm/libjsc.so
2019-02-07 14:22:50.203 10137-10137/? A/DEBUG:     #10 pc 0029402f  /data/app/com.xyzor.timer-1/lib/arm/libjsc.so
2019-02-07 14:22:50.203 10137-10137/? A/DEBUG:     #11 pc 0005e669  /data/app/com.xyzor.timer-1/lib/arm/libjsc.so (JSValueCreateJSONString+72)
2019-02-07 14:22:50.203 10137-10137/? A/DEBUG:     #12 pc 0003b3b9  /data/app/com.xyzor.timer-1/lib/arm/libreactnativejni.so (_ZNK8facebook5react5Value12toJSONStringEj+20)
2019-02-07 14:22:50.203 10137-10137/? A/DEBUG:     #13 pc 00033c3b  /data/app/com.xyzor.timer-1/lib/arm/libreactnativejni.so (_ZN8facebook5react11JSCExecutor19flushQueueImmediateEONS0_5ValueE+26)
2019-02-07 14:22:50.203 10137-10137/? A/DEBUG:     #14 pc 00033d6f  /data/app/com.xyzor.timer-1/lib/arm/libreactnativejni.so (_ZN8facebook5react11JSCExecutor25nativeFlushQueueImmediateEjPKPK13OpaqueJSValue+86)
2019-02-07 14:22:50.203 10137-10137/? A/DEBUG:     #15 pc 00034ab1  /data/app/com.xyzor.timer-1/lib/arm/libreactnativejni.so
2019-02-07 14:22:50.203 10137-10137/? A/DEBUG:     #16 pc 0004eda9  /data/app/com.xyzor.timer-1/lib/arm/libjsc.so
2019-02-07 14:22:50.203 10137-10137/? A/DEBUG:     #17 pc 0012fa9b  /data/app/com.xyzor.timer-1/lib/arm/libjsc.so
2019-02-07 14:22:50.203 10137-10137/? A/DEBUG:     #18 pc 0012f60d  /data/app/com.xyzor.timer-1/lib/arm/libjsc.so
2019-02-07 14:22:52.073 1257-10138/? W/ActivityManager:   Force finishing activity com.xyzor.timer/host.exp.exponent.experience.ShellAppActivity
2019-02-07 14:22:52.140 1257-1272/? D/ViewRootImpl@2042207[timer]: ThreadedRenderer.create() translucent=true
2019-02-07 14:22:52.142 1257-1272/? D/WindowManager: openInputChannel mInputChannel: a585ad2 Application Error: com.xyzor.timer (server)
2019-02-07 14:22:52.144 1257-1272/? D/ViewRootImpl@2042207[timer]: setView = DecorView@83d521e[timer] touchMode=true
2019-02-07 14:22:52.162 7102-10144/? W/PkgUtils: p: com.xyzor.timer, u:0
2019-02-07 14:22:52.167 1257-1272/? D/ViewRootImpl@2042207[timer]: dispatchAttachedToWindow
2019-02-07 14:22:52.194 1257-1272/? D/ViewRootImpl@2042207[timer]: Relayout returned: oldFrame=[0,0][0,0] newFrame=[256,816][1280,1279] result=0x27 surface={isValid=true 547307523072} surfaceGenerationChanged=true
2019-02-07 14:22:52.194 1257-1272/? D/ViewRootImpl@2042207[timer]: mHardwareRenderer.initialize() mSurface={isValid=true 547307523072} hwInitialized=true
2019-02-07 14:22:52.197 1257-1272/? D/ViewRootImpl@2042207[timer]: MSG_WINDOW_FOCUS_CHANGED 1
2019-02-07 14:22:52.197 1257-1272/? D/ViewRootImpl@2042207[timer]: mHardwareRenderer.initializeIfNeeded()#2 mSurface={isValid=true 547307523072}
2019-02-07 14:22:52.209 7187-7204/? W/PkgUtils: p: com.xyzor.timer, u:0
2019-02-07 14:22:52.230 1257-1272/? D/WindowManager: finishDrawingWindow: Window{a585ad2d0 u0 Application Error: com.xyzor.timer} mDrawState=DRAW_PENDING
2019-02-07 14:22:52.231 1257-1272/? D/ViewRootImpl@2042207[timer]: MSG_RESIZED_REPORT: frame=Rect(256, 816 - 1280, 1279) ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
2019-02-07 14:22:52.236 1257-1272/? D/WindowManager: finishDrawingWindow: Window{a585ad2d0 u0 Application Error: com.xyzor.timer} mDrawState=HAS_DRAWN
2019-02-07 14:22:52.448 1257-1385/? I/WindowManager: WIN DEATH: Window{2a8ca6fd0 u0 com.xyzor.timer/host.exp.exponent.experience.ShellAppActivity}
2019-02-07 14:22:52.449 1257-1385/? D/WindowManager: disposeInputChannel mInputChannel: 2a8ca6f com.xyzor.timer/host.exp.exponent.experience.ShellAppActivity (server)
2019-02-07 14:22:52.449 1257-2210/? I/ActivityManager: Process com.xyzor.timer (pid 9982) has died(864,760)

常规信息:

  • 我正在将Expo与Expo SDK 31一起使用,并响应本机0.57。
  • 我能够通过adb logcat登录该应用程序。
  • 我在原生android开发方面经验不足

1 个答案:

答案 0 :(得分:0)

问题是我正在将一个对象传递给JSON.stringify(),该对象太大,以至于应用程序没有足够的内存来存储该字符串。

  1. 理想的解决方案

切换到流媒体方法。像JSONStream

对我来说这是不可能的,因为我正在使用Expo(也许甚至在RN中也无法做到)

  1. 将数据拆分为单独的文件

由于问题的根源在于您不能将太大的对象/字符串传递给JSON。[stringify,parse],我只是简单地将数据拆分为不同的文件。

幸运的是,我在自定义存储引擎中使用了redux-persist,因此我能够修改必要的方法来处理这些数据。