-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Android: "FATAL EXCEPTION: mqt_js" / Error calling function: RCTDeviceEventEmitter:emit / - malformed JSON parsing in RN's android native code #10756
Comments
Hello! You're unlikely to get much help until you can provide a reproducible example :( Please keep trying and let us know when you have it. |
I narrowed it down. BUG: Using fetch() and then doing response.json() when the server sends Expectation: JS exception, not crash. On Nov 6, 2016 10:04 AM, "Brent Vatne" notifications@github.com wrote:
|
@GeoffreyPlitt - that's no fun. Does that happen in release mode or debug or both? |
Both On Nov 6, 2016 10:14 AM, "Brent Vatne" notifications@github.com wrote:
|
@lacker - any idea who this should be assigned to? |
I don't have someone who is going to jump on and fix this, but if there is a pull request that fixes this I would be happy to prioritize its review. |
@GeoffreyPlitt I tried to reproduce this case but failed ....
After click the |
Update: Yeah I just re-tested this and you're right, it's not caused by fetch() / response.json(). I'm now convinced that this is some background android process. New crash logs from today:
What is mqt_js and how can we find out why it causes Error calling function: RCTDeviceEventEmitter:emit ? |
More: This seems to only happen in release-mode i.e. It does not happen in debug mode. |
This is another case where reproducing it is going to make it easier to debug. What is the simplest app that reproduces this? |
Hey there, All working properly on iOS but it doesn't work with Android.
Ignoring the other parts which are not causing this issue what you get here is a
On iOS I can properly access the raw response object. On Android the error is the same as the OP, it crashes before to even resolve the promise (it's not related to any call inside the promise, the promise never runs). I was digging into this problem but I'm unsure if with Android (5.1.1 here for tests) it finds a native implementation or it's using the whatwg-fetch (tbh, I don't quite understand where in react native could it be found natively – i'd say it's always from the library, am I wrong?). I'm new into looking at RN codebase if you can give to me some advise I can try to get more info. |
Hey there, |
Crash on Android, but OK on iOS fetch(pngURL)
.then(response => response.text())
.then(base64Data => {}); |
In my case the problem was that fetch("URL") method expected JSON in response, however I was passing stub URL which was an url to an image, e.g. http://test.com/test.png . FYI: List of open APIs https://github.com/toddmotto/public-apis |
it happens when I do
and it's only crash on Android release mode. Hence, I switched to |
Same error here when fetching an image :/ |
This is happening to me on android 5.0.1 when attempting to fetch(URL) an image. It seems to be happening due to lack of support for 'blob'. I feel like this should be documented in the networking page since the tutorial seems to indicate you can use the fetch api in it's entirety. A workaround is to use the react-native-fetch-blob library. |
I got the same crash. I try to use |
I'm getting the same crash when requesting an HTML page. Don't have an iOS device to test on, but this crash occurs on my Pixel XL with latest |
same problem here. trying to fetch image info from http head response. curl -I http://m.newsmth.net/att/inbox/52/89252 |
fetch('http://s1.dwstatic.com/group1/M00/F5/15/af09c9472255fc101863cf4929a4daff.gif') |
Same error
Device : |
same problem here in Android 6. @langjun |
Hello, Any update on this issue? How can I fix this bug ? :( |
@zolaahihi sounds like you'd have to trace through the c++ and debug it. Let us know if you have questions. |
Just a head's up, this error occured for us when we sent |
It's a bug caused by the following code: Value Value::fromDynamic(JSContextRef ctx, const folly::dynamic& value) {
// JavaScriptCore's iOS APIs have their own version of this direct conversion.
// In addition, using this requires exposing some of JSC's private APIs,
// so it's limited to non-apple platforms and to builds that use the custom JSC.
// Otherwise, we use the old way of converting through JSON.
#if USE_FAST_FOLLY_DYNAMIC_CONVERSION
// Defer GC during the creation of the JSValue, as we don't want
// intermediate objects to be collected.
// We could use JSValueProtect(), but it will make the process much slower.
JSDeferredGCRef deferGC = JSDeferGarbageCollection(ctx);
// Set a global lock for the whole process,
// instead of re-acquiring the lock for each operation.
JSLock(ctx);
JSValueRef jsVal = Value::fromDynamicInner(ctx, value);
JSUnlock(ctx);
JSResumeGarbageCollection(ctx, deferGC);
return Value(ctx, jsVal);
#else
auto json = folly::toJson(value);
return fromJSON(String(ctx, json.c_str()));
#endif
}
if we change the code to: folly::json::serialization_opts opts;
opts.encode_non_ascii = true;
opts.skip_invalid_utf8 = true;
auto json = folly::json::serialize(value, opts); It will not crash. But the result may be incorrect. |
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions. |
This comment has been minimized.
This comment has been minimized.
@huangd0ng what lines are changed exactly? auto json = folly::toJson(value); should be folly::json::serialization_opts opts;
opts.encode_non_ascii = true;
opts.skip_invalid_utf8 = true;
auto json = folly::json::serialize(value, opts); ? that could be a PR |
@morenoh149 It is that line. My change just prevents it from crashing. But when you fetch binary data, you may not get correct result. So I do not think we should fix it this way. |
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions. |
Hi, I am getting this issue in my app's on of the @ReactMethod. My observations are that this issue is occuring only on 32 bit android devices and not 64 bit. I am not sure if its only on emulator or actual device too. I am not having any 32-bit device with me so checked only on emulator. |
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions. |
Just for the bot. No activity means it's not solved. |
I am having this issue too, has anyone been able to solve it? I am using react native version |
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions. |
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information. |
Description
Calling fetch() and expecting JSON results (i.e. using
response.json()
) will crash if server sends malformed JSON. Error/logging system prints "Failed to create String from JSON:" and then does NOT print the JSON (the problem this ticket IS about).#9117 promised to fix this, but did not.
Reproduction
Call fetch() and then response.json() with a server that returns bad JSON.
Additional Information
Here's an example log:
Questions:
The text was updated successfully, but these errors were encountered: