React-native: [iOS] Crash in Value.cpp line 34 - facebook::react::Value::toJSONString(unsigned int) const

Created on 26 Sep 2017  Â·  31Comments  Â·  Source: facebook/react-native

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

Environment:
OS: macOS Sierra 10.12.6
Node: 8.5.0
Yarn: 1.0.1
npm: 5.3.0
Watchman: 4.6.0
Xcode: Xcode 9.0 Build version 9A235
Android Studio: 2.3 AI-162.4069837

Packages: (wanted => installed)
react: 16.0.0-alpha.12 => 16.0.0-alpha.12
react-native: 0.48.3 => 0.48.3

Target Platform: iOS

Crash

Hi, we're getting a crash on iOS in the internals of React Native. I haven't been able to reproduce, but you can find the Crashlytics stack trace here : http://crashes.to/s/d52d9bce313

Crashed: com.facebook.react.JavaScript
EXC_BREAKPOINT 0x0000000186892ae8
--

12 Truckfly                       0x10072d4fc facebook::react::Value::toJSONString(unsigned int) const (Value.cpp:34)
13 Truckfly                       0x100753fa0 facebook::react::JSCExecutor::flushQueueImmediate(facebook::react::Value&&) (memory:4050)
14 Truckfly                       0x1007544a0 facebook::react::JSCExecutor::nativeFlushQueueImmediate(unsigned long, OpaqueJSValue const* const*) (JSCExecutor.cpp:588)
15 Truckfly                       0x100754c78 OpaqueJSValue const* (*facebook::react::(anonymous namespace)::exceptionWrapMethod<&(facebook::react::JSCExecutor::nativeFlushQueueImmediate(unsigned long, OpaqueJSValue const* const*))>())(OpaqueJSContext const*, OpaqueJSValue*, OpaqueJSValue*, unsigned long, OpaqueJSValue const* const*, OpaqueJSValue const**)::funcWrapper::call(OpaqueJSContext const*, OpaqueJSValue*, OpaqueJSValue*, unsigned long, OpaqueJSValue const* const*, OpaqueJSValue const**) (JSCExecutor.cpp:64)



Crashed: com.facebook.react.JavaScript
0 JavaScriptCore 0x186892ae8 bmalloc::Heap::allocateLarge(std::__1::lock_guard&, unsigned long, unsigned long) + 24
1 JavaScriptCore 0x186892adc bmalloc::Heap::allocateLarge(std::__1::lock_guard&, unsigned long, unsigned long) + 12
2 JavaScriptCore 0x186890a1c bmalloc::Allocator::allocateLarge(unsigned long) + 92
3 JavaScriptCore 0x185eeab88 WTF::StringImpl::createUninitialized(unsigned int, unsigned short&) + 64
4 JavaScriptCore 0x185eeaa40 WTF::StringBuilder::allocateBufferUpConvert(unsigned char const
, unsigned int) + 48
5 JavaScriptCore 0x18687d58c WTF::StringBuilder::appendQuotedJSONString(WTF::String const&) + 160
6 JavaScriptCore 0x18660f0c0 JSC::Stringifier::appendStringifiedValue(WTF::StringBuilder&, JSC::JSValue, JSC::Stringifier::Holder const&, JSC::PropertyNameForFunctionCall const&) + 1624
7 JavaScriptCore 0x186610914 JSC::Stringifier::Holder::appendNextProperty(JSC::Stringifier&, WTF::StringBuilder&) + 3048
8 JavaScriptCore 0x18660f594 JSC::Stringifier::appendStringifiedValue(WTF::StringBuilder&, JSC::JSValue, JSC::Stringifier::Holder const&, JSC::PropertyNameForFunctionCall const&) + 2860
9 JavaScriptCore 0x18660e884 JSC::Stringifier::stringify(JSC::Handle) + 268
10 JavaScriptCore 0x186613168 JSC::JSONStringify(JSC::ExecState, JSC::JSValue, unsigned int) + 272
11 JavaScriptCore 0x186657704 JSValueCreateJSONString + 180
12 Truckfly 0x10072d4fc facebook::react::Value::toJSONString(unsigned int) const (Value.cpp:34)
13 Truckfly 0x100753fa0 facebook::react::JSCExecutor::flushQueueImmediate(facebook::react::Value&&) (memory:4050)
14 Truckfly 0x1007544a0 facebook::react::JSCExecutor::nativeFlushQueueImmediate(unsigned long, OpaqueJSValue const
const) (JSCExecutor.cpp:588)
15 Truckfly 0x100754c78 OpaqueJSValue const
(facebook::react::(anonymous namespace)::exceptionWrapMethod<&(facebook::react::JSCExecutor::nativeFlushQueueImmediate(unsigned long, OpaqueJSValue const const))>())(OpaqueJSContext const, OpaqueJSValue, OpaqueJSValue, unsigned long, OpaqueJSValue const* const, OpaqueJSValue const)::funcWrapper::call(OpaqueJSContext const, OpaqueJSValue, OpaqueJSValue, unsigned long, OpaqueJSValue const* const, OpaqueJSValue const) (JSCExecutor.cpp:64)
16 JavaScriptCore 0x1865becac long long JSC::APICallbackFunction::call(JSC::ExecState
) + 456
17 JavaScriptCore 0x185f12270 JSC::LLInt::setUpCall(JSC::ExecState, JSC::Instruction, JSC::CodeSpecializationKind, JSC::JSValue, JSC::LLIntCallLinkInfo) + 456
18 JavaScriptCore 0x1866a65c0 llint_entry + 26416
19 JavaScriptCore 0x1866a656c llint_entry + 26332
20 JavaScriptCore 0x1866a656c llint_entry + 26332
21 JavaScriptCore 0x1866a65d0 llint_entry + 26432
22 JavaScriptCore 0x1866a656c llint_entry + 26332
23 JavaScriptCore 0x1866a656c llint_entry + 26332
24 JavaScriptCore 0x1866a6904 llint_entry + 27252
25 JavaScriptCore 0x1866a656c llint_entry + 26332
26 JavaScriptCore 0x1866a65d0 llint_entry + 26432
27 JavaScriptCore 0x1866a656c llint_entry + 26332
28 JavaScriptCore 0x1866a65d0 llint_entry + 26432
29 JavaScriptCore 0x1866a656c llint_entry + 26332
30 JavaScriptCore 0x1866a65d0 llint_entry + 26432
31 JavaScriptCore 0x1866a65d0 llint_entry + 26432
32 JavaScriptCore 0x1866a656c llint_entry + 26332
33 JavaScriptCore 0x1866a656c llint_entry + 26332
34 JavaScriptCore 0x1866a6904 llint_entry + 27252
35 JavaScriptCore 0x1866a65d0 llint_entry + 26432
36 JavaScriptCore 0x1866a656c llint_entry + 26332
37 JavaScriptCore 0x1866a656c llint_entry + 26332
38 JavaScriptCore 0x1866a656c llint_entry + 26332
39 JavaScriptCore 0x1866a656c llint_entry + 26332
40 JavaScriptCore 0x1866a656c llint_entry + 26332
41 JavaScriptCore 0x1866a656c llint_entry + 26332
42 JavaScriptCore 0x1866a656c llint_entry + 26332
43 JavaScriptCore 0x1866a6a10 llint_entry + 27520
44 JavaScriptCore 0x1866a65d0 llint_entry + 26432
45 JavaScriptCore 0x1866a656c llint_entry + 26332
46 JavaScriptCore 0x1866a6a10 llint_entry + 27520
47 JavaScriptCore 0x1866a656c llint_entry + 26332
48 JavaScriptCore 0x1866a65d0 llint_entry + 26432
49 JavaScriptCore 0x1866a656c llint_entry + 26332
50 JavaScriptCore 0x18669fcc8 vmEntryToJavaScript + 264
51 JavaScriptCore 0x186589710 JSC::JITCode::execute(JSC::VM
, JSC::ProtoCallFrame) + 164
52 JavaScriptCore 0x185f16610 JSC::Interpreter::executeCall(JSC::ExecState
, JSC::JSObject, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) + 416
53 JavaScriptCore 0x18622273c JSC::profiledCall(JSC::ExecState
, JSC::ProfilingReason, JSC::JSValue, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) + 164
54 JavaScriptCore 0x185f16384 JSObjectCallAsFunction + 636
55 Truckfly 0x10072e364 facebook::react::Object::callAsFunction(OpaqueJSValue, int, OpaqueJSValue const const) const (Value.cpp:189)
56 Truckfly 0x100753860 facebook::react::JSCExecutor::callFunction(std::__1::basic_string, std::__1::allocator > const&, std::__1::basic_string, std::__1::allocator > const&, folly::dynamic const&) (Value.h:46)
57 Truckfly 0x100752d90 std::__1::function) const (functional:1817)
58 Truckfly 0x1006e1294 facebook::react::tryAndReturnError(std::__1::function 59 Truckfly 0x1006da8c0 facebook::react::RCTMessageThread::tryFunc(std::__1::function 60 CoreFoundation 0x181fb130c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 20
61 CoreFoundation 0x181fb0b28 __CFRunLoopDoBlocks + 288
62 CoreFoundation 0x181faee1c __CFRunLoopRun + 1884
63 CoreFoundation 0x181ededa4 CFRunLoopRunSpecific + 424
64 Truckfly 0x1006b9f78 -[RCTCxxBridge runJSRunLoop] (RCTCxxBridge.mm:220)
65 Foundation 0x182af7318 __NSThread__start__ + 996
66 libsystem_pthread.dylib 0x1810c568c _pthread_body + 240
67 libsystem_pthread.dylib 0x1810c559c _pthread_body + 282
68 libsystem_pthread.dylib 0x1810c2cb4 thread_start + 4

Does anyone see the same crash?

AsyncStorage Ran Commands Locked

Most helpful comment

@cosmith my finding were that the error happened when trying to store large json data to AsyncStorage on iOS. My example was a json string 52000000 characters long.

I ended up getting around this issue by using realm as a storage engine for redux-persist, and also by splitting the reducer for that data into 16 separate reducers that are combined by a selector so I can easily use the data.

I put the details in this answer in stack overflow - https://stackoverflow.com/a/48582319/3672622

All 31 comments

Did any of ya'll come up with a workaround for this? We're seeing this error log pretty consistently in production, and users confirm it results in a crash, but we're not able to recreate it on our own.

Any fix for this yet?

has a workaround been found yet?

+1 seeing the same behavior

I’ve been seeing these occasionally, too. No idea what causes it.

Has anyone found a fix for this yet?

I get about a thousand of these daily. Could really use assistance in a work around or fix. The crash reports aren't helpful at identifying the cause.

@facebook-github-bot label iOS

+1 same error

react: 16.0.0-alpha.12
react-native: 0.47.1

One thing that's consistent: OS Version: iPhone OS 11.0.3 (15A432)
Can someone share their package.json or list of dependencies?
Want to check if there is any common package that could be leading to this.

+1 same error
iPad 2
iOS 9.3.5

Here are my package.json dependencies, if it helps:

"dependencies": {
"aws-sdk-react-native-core": "../aws/aws-sdk-react-native-source/aws-sdk-react-native-core-0.0.2b.tgz",
"aws-sdk-react-native-dynamodb": "../aws/aws-sdk-react-native-source/aws-sdk-react-native-dynamodb-0.0.1b.tgz",
"react": "^16.0.0-alpha.12",
"react-native": "^0.48.3",
"react-native-app-store-review": "0.0.3",
"react-native-deprecated-custom-components": "^0.1.1",
"react-native-device-info": "^0.13.0",
"react-native-fabric": "^0.5.1",
"react-native-keyboard-aware-scroll-view": "^0.3.0",
"react-native-keychain": "^1.0",
"react-native-scrollable-tab-view": "^0.7.4",
"react-native-sound": "^0.10.4",
"react-navigation": "^1.0.0-beta.12",
"react-timer-mixin": "^0.13.3"
},

I have it on these versions of iOS:

11.2.1  72%
11.1.2  12%
11.0.3  4%
11.2.0  2%
11.1.0  2%
11.1.1  2%
11.0.2  2%
11.0.1  1%
11.0.0  1%
11.2.2  1%
11.2.5  1%
    "dependencies": {
        "bluebird": "~3.5.0",
        "blueimp-md5": "^2.10.0",
        "core-js": "^2.5.3",
        "filepicker-js": "~2.4.17",
        "final-form": "^3.0.0",
        "fs": "https://github.com/cosmith/fs.git",
        "lodash": "~4.17.4",
        "lokijs": "~1.5.0",
        "moment": "^2.19.1",
        "node-polyglot": "~2.2.2",
        "normalizr": "~3.2.3",
        "pre-commit": "^1.2.2",
        "raven-js": "^3.17.0",
        "react": "16.0.0-alpha.12",
        "react-final-form": "^2.1.0",
        "react-native": "0.48.4",
        "react-native-background-fetch": "^2.1.0",
        "react-native-background-geolocation": "~2.9.3",
        "react-native-check-box": "^2.0.1",
        "react-native-code-push": "~5.1.1-beta",
        "react-native-deprecated-custom-components": "^0.1.1",
        "react-native-device-info": "~0.12.1",
        "react-native-drawer": "~2.5.0",
        "react-native-fabric": "~0.5.1",
        "react-native-facebook-account-kit": "^0.9.0",
        "react-native-fbsdk": "https://github.com/truckfly/react-native-fbsdk.git",
        "react-native-fetch-blob": "~0.10.8",
        "react-native-gifted-chat": "~0.2.7",
        "react-native-image-picker": "~0.26.7",
        "react-native-keep-awake": "^2.0.6",
        "react-native-keyboard-aware-scroll-view": "~0.4.1",
        "react-native-keyboard-spacer": "~0.4.1",
        "react-native-localization": "~0.2.1",
        "react-native-push-notification": "3.0.1",
        "react-native-ux-cam": "~4.4.0",
        "react-redux": "~5.0.6",
        "redux": "~3.7.2",
        "redux-logger": "~3.0.6",
        "redux-raven-middleware": "^1.2.0",
        "redux-thunk": "~2.2.0",
        "whatwg-fetch": "^2.0.3"
    }

@pjktk2 Only common packages:

"react": "16.0.0-alpha.12"
"react-native": "0.47.1"

Though I am on 0.47.1

I'm also getting this in RN 0.52.0
One of my team seems to be able to replicate it, so I'm going to try to narrow down the trigger if I can replicate it as well

"dependencies": {
    "@expo/ex-navigation": "^3.1.0",
    "@expo/react-native-action-sheet": "^1.0.1",
    "buffer": "^5.0.7",
    "color": "^2.0.0",
    "email-validator": "^1.1.1",
    "emojione": "^3.1.2",
    "es6-promise-debounce": "^1.0.1",
    "flat-to-nested": "^1.0.2",
    "lodash": "^4.17.4",
    "moment": "^2.19.1",
    "moment-timezone": "^0.5.14",
    "prop-types": "^15.6.0",
    "pusher-js": "^4.2.1",
    "raven-js": "^3.19.1",
    "react": "16.2.0",
    "react-native": "0.52.0",
    "react-native-animatable": "^1.2.4",
    "react-native-animated-picker": "^0.1.0",
    "react-native-background-timer": "^1.3.0",
    "react-native-camera": "^0.12.0",
    "react-native-code-push": "v5.2.0-beta",
    "react-native-extended-stylesheet": "^0.8.0",
    "react-native-fabric": "^0.5.1",
    "react-native-fabric-crashlytics": "^0.1.8",
    "react-native-fetch-blob": "papertrailio/react-native-fetch-blob#NullPointerException",
    "react-native-fs": "^2.8.4",
    "react-native-http-cache": "papertrailio/react-native-http-cache#rn-0.48",
    "react-native-hyperlink": "^0.0.11",
    "react-native-i18n": "^2.0.9",
    "react-native-image-resizer": "^1.0.0",
    "react-native-intercom": "^9.0.0",
    "react-native-keep-awake": "^2.0.6",
    "react-native-keyboard-aware-scroll-view": "^0.3.0",
    "react-native-keyboard-spacer": "^0.4.1",
    "react-native-keychain": "^2.0.0-rc",
    "react-native-orientation": "^3.1.0",
    "react-native-parallax-scroll-view": "^0.20.1",
    "react-native-pdf": "^2.0.3",
    "react-native-permissions": "^1.0.1",
    "react-native-progress": "^3.4.0",
    "react-native-restart": "^0.0.4",
    "react-native-scrollable-tab-view": "skv-headless/react-native-scrollable-tab-view#74a0b3fc3f5b69b49b93e0e5f9b0d9089da757c5",
    "react-native-spinkit": "^1.1.1",
    "react-native-timer": "^1.3.1",
    "react-native-userdefaults-ios": "^0.1.3",
    "react-native-uuid": "^1.4.9",
    "react-native-vector-icons": "^4.4.2",
    "react-native-version-number": "^0.3.0",
    "react-redux": "^5.0.6",
    "redux": "^3.7.2",
    "redux-form": "^7.1.2",
    "redux-logger": "^3.0.6",
    "redux-persist": "^4.8.3",
    "redux-persist-filesystem-storage": "^1.1.0",
    "redux-persist-migrate": "^5.0.0",
    "redux-thunk": "^2.2.0",
    "reselect": "^3.0.1",
    "tree-model": "^1.0.6"
  }

@robwalkerco any progress? Are you able to replicate it? The stack trace isn't very helpful :/

@cosmith my finding were that the error happened when trying to store large json data to AsyncStorage on iOS. My example was a json string 52000000 characters long.

I ended up getting around this issue by using realm as a storage engine for redux-persist, and also by splitting the reducer for that data into 16 separate reducers that are combined by a selector so I can easily use the data.

I put the details in this answer in stack overflow - https://stackoverflow.com/a/48582319/3672622

@robwalkerco But I ain't using AsyncStorage :(

@princenaman perhaps there is somewhere else in your code that’s transferring a large bit of data across the JavaScript bridge? That’s where I guess the crash is happening.

Or perhaps some other package you are using that’s using AsyncStorage behind the scenes?

The largest data that I am transferring is a JSON string about 5000 characters long.
Will check my packages though.

Thanks @robwalkerco. Did the crash always happen with your ~50Mb JSON string, or occasionally? Looking back at my crashes in production, some occurrences could have been coincident with writing 1-3Mb JSON strings to AsyncStorage, but (a) probably not all occurrences, (b) the app has likely written larger JSON strings a number of times without seeing this crash.
Either way, I'm now instrumenting these calls to AsyncStorage with the size of the JSON string, so I'll know if it crashes in SetItem() and what the size of the string was.

Incidentally, my Crashlytics reports all put the available RAM at < 10% on these crashes. For an iPad 2 I think that's less than 50Mb free. Make a few copies of the string, maybe the memory usage report over-reported free memory...it's conceivable this is a memory problem. I'd love to test this hypothesis too, but RN doesn't have a hook for receiving low memory warnings though, right?

@pjktk2 when I managed to replicate the crash (more by chance than anything) it was only happening when storing a large json string, and was happening consistently with that json (at least on my phone)

I’ve not looked at memory availability, but will check our error reporting for any clues there.

Sounds like you are well ahead of me in terms to tracking this bug down, so I will be interested to hear your findings!

@pjktk2 I think your right about the memory issue. All the crashes happened when there was less than 5% RAM available on the device.

+1 on this, in the latest version of our app the stack trace changed to bmalloc::Heap::allocateLarge
image

Any tips on reducing memory usage with RN?

Can it be because I am storing data in Realm?
screen shot 2018-02-13 at 11 29 40 am

This issue was introduced for us when upgrading from BatchedBridge to CxxBridge (react native's C++ bridge), which was made the default in react-native v0.45.0. We see thousands of crashes a day for about 6-7% of our users.

I was able to replicate the crash by sending a large string (~100,000,000 characters long) to a custom NativeModule function that does nothing. The CxxBridge just isn't able to handle passing a string that large from JS to Native. It could be memory related, but doesn't happen when using BatchedBridge instead of CxxBridge.

This definitely isn't limited to AsyncStorage, and could happen with any package or code that sends a large string across the bridge. If you're using redux-persist, persisting less data or blacklisting large reducers would fix the issue for now. Ideally the bridge would be able to handle larger strings...

Thanks for posting this! It looks like you may not be using the latest version of React Native, v0.53.0, released on January 2018. Can you make sure this issue can still be reproduced in the latest version?

I am going to close this, but please feel free to open a new issue if you are able to confirm that this is still a problem in v0.53.0 or newer.

How to Contribute • What to Expect from Maintainers

I’ll double check next week, but I was able to replicate this issue in the latest version of react native. It was introduced in react native v0.45.0. I think it would be better to keep this particular issue open as it has a lot of context.

Just a follow up to @cosmith asking about reducing memory usage vis a vis workarounds:

A few days ago I had a 100% reproducible case with this bug and I used the "opportunity" to clean up a bit of memory usage. I was storing a 6Mb string on a single AsyncStorage.setItem(). I profiled the app and found that memory usage spiked 8-10x that amount (i.e. 50-65Mb) when accessing that item. That spike was what caused the crash, every time.
Some of the spike be due to my post-processing code, but I think a lot was due to the string being copied and re-copied on its way through native code. In this case, I chopped up the item into many smaller parts (using the same JS post-processing code!) and the spike disappeared.
Interestingly, while my crude performance testing on the iOS simulator showed a performance hit of 4x, running on a device in production I couldn’t see a noticeable performance difference. Note that the performance tests on a real device were (a) stopwatch and not instrumented counters, and (b) done in a warm-cache environment, not cold-cache. YMMV.
This may or may not be helpful to you, but if you can avoid passing large strings though setItem/getItem, even if it involves slicing them up and re-composing them, it might help.

Hi @pjktk2, thanks for the followup. I was also able to make this crash disappear by saving the big blob of data that I had to the filesystem instead of AsyncStorage.

I can reproduce this crash in my project 100%, every time I try to use 'console.tron.log'(the log helper of reactotron-react-native) to output the params of an event(like onBlur of TextInput),the app will crash after a few seconds without any response, maybe this is useful for locating the issue.
<TextInput onBlur={(e)=>{ console.tron.log('blur',e); }}


"react-native": "0.54.1",
"reactotron-react-native": "^2.0.0-beta.1",

@cosmith If you don't mind me asking, how did you achieve this? I'm serialising a 9MB object structure to JSON and writing it to disk with rn-fetch-blob, but it seems to crash quite often.

I opened a new issue since the crash is still happening on the latest version of react-native. If anyone wants to chime in there, feel free :)

Was this page helpful?
0 / 5 - 0 ratings