Skip to content
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

com.microsoft.codepush.react.CodePushMalformedDataException Unable to parse contents of [..]/codepush.json #1149

Closed
maxkomarychev opened this issue Jan 18, 2018 · 21 comments

Comments

@maxkomarychev
Copy link

Hi,

this is the crash report I've got from crash-analytics service. I wasn't able to reproduce it myself however whatever happens the codepush should not crash, it should safely fallback to original bundle if error happened during it's initialization.

Expected Behavior

CodePush should not crash the app. It should safely fallback to original bundle.

Actual Behavior

App crashes.

java.lang.RuntimeException An error occurred while executing doInBackground() 
    AsyncTask.java:318 android.os.AsyncTask$3.done
    FutureTask.java:354 java.util.concurrent.FutureTask.finishCompletion
    FutureTask.java:223 java.util.concurrent.FutureTask.setException
    FutureTask.java:242 java.util.concurrent.FutureTask.run
    ThreadPoolExecutor.java:1133 java.util.concurrent.ThreadPoolExecutor.runWorker
    ThreadPoolExecutor.java:607 java.util.concurrent.ThreadPoolExecutor$Worker.run
    Thread.java:761 java.lang.Thread.run


Caused by: com.microsoft.codepush.react.CodePushMalformedDataException Unable to parse contents of /data/user/0/my.package.name/files/CodePush/codepush.json, the file may be corrupted. 
    CodePushUtils.java:198 com.microsoft.codepush.react.CodePushUtils.getJsonObjectFromFile
    CodePushUpdateManager.java:55 com.microsoft.codepush.react.CodePushUpdateManager.getCurrentPackageInfo
    CodePushUpdateManager.java:105 com.microsoft.codepush.react.CodePushUpdateManager.getCurrentPackageHash
    CodePushUpdateManager.java:115 com.microsoft.codepush.react.CodePushUpdateManager.getCurrentPackage
    CodePushNativeModule.java:295 com.microsoft.codepush.react.CodePushNativeModule$4.doInBackground
    CodePushNativeModule.java:292 com.microsoft.codepush.react.CodePushNativeModule$4.doInBackground
    AsyncTask.java:304 android.os.AsyncTask$2.call
    FutureTask.java:237 java.util.concurrent.FutureTask.run
    ThreadPoolExecutor.java:1133 java.util.concurrent.ThreadPoolExecutor.runWorker
    ThreadPoolExecutor.java:607 java.util.concurrent.ThreadPoolExecutor$Worker.run
    Thread.java:761 java.lang.Thread.run


Caused by: org.json.JSONException End of input at character 0 of  
    JSONTokener.java:449 org.json.JSONTokener.syntaxError
    JSONTokener.java:97 org.json.JSONTokener.nextValue
    JSONObject.java:156 org.json.JSONObject.<init>
    JSONObject.java:173 org.json.JSONObject.<init>
    CodePushUtils.java:195 com.microsoft.codepush.react.CodePushUtils.getJsonObjectFromFile
    CodePushUpdateManager.java:55 com.microsoft.codepush.react.CodePushUpdateManager.getCurrentPackageInfo
    CodePushUpdateManager.java:105 com.microsoft.codepush.react.CodePushUpdateManager.getCurrentPackageHash
    CodePushUpdateManager.java:115 com.microsoft.codepush.react.CodePushUpdateManager.getCurrentPackage
    CodePushNativeModule.java:295 com.microsoft.codepush.react.CodePushNativeModule$4.doInBackground
    CodePushNativeModule.java:292 com.microsoft.codepush.react.CodePushNativeModule$4.doInBackground
    AsyncTask.java:304 android.os.AsyncTask$2.call
    FutureTask.java:237 java.util.concurrent.FutureTask.run
    ThreadPoolExecutor.java:1133 java.util.concurrent.ThreadPoolExecutor.runWorker
    ThreadPoolExecutor.java:607 java.util.concurrent.ThreadPoolExecutor$Worker.run
    Thread.java:761 java.lang.Thread.run

Reproducible Demo

  • If you can't reproduce the bug on it, provide us as much info as possible about your project

I do have this
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle" line in build.gradle

Environment

  • react-native-code-push version: 5.2.1
  • react-native version: 0.50.3
  • iOS/Android/Windows version: android 7.0
  • Does this reproduce on a debug build or release build?
  • Does this reproduce on a simulator, or only on a physical device?
    Happened dozen of times on release build on physical device.
@sergey-akhalkov
Copy link
Contributor

sergey-akhalkov commented Jan 19, 2018

Hi @maxkomarychev, thanks for reaching us.

CodePush should not crash the app. It should safely fallback to original bundle.

Absolutely agreed, to have good UX we definitely should not crash an app while installing broken CodePush update. Currently, we are actively working on CodePush native SDKs (both Android and Apple) migration to the App Center native SDKs, while migrating we are going to fix such kind of problems in addition to general rollbacks enhancement (add an ability to see the reason of rollbacks). The migration process will take some time and when we have it finished - you'll be able to use appcenter-codepush service from the https://github.com/Microsoft/AppCenter-SDK-React-Native/ with all the improvements I've listed above.

Please also let me know if you see any other issues or have any questions.

@maxkomarychev
Copy link
Author

maxkomarychev commented Jan 19, 2018

thanks! do you have any ETA/roadmap on when those new SDKs will be available?

@sergey-akhalkov sergey-akhalkov removed their assignment Feb 15, 2018
@rodrigoalmeidaee
Copy link

We have this issue reported in our app too both in Sentry and Crashlytics, and likewise haven't been able to reproduce it ourselves.

Our current 7-day metrics for this crash indicate that out of our about 2k weekly active users, 40 users see this crash every week (they're not the same week after week BTW), so roughly 2% of our userbase is affected. It is not a major issue for us, but it is also not rare enough that it doesn't produce some discomfort.

We don't know what the root cause is, but are considering working on a fix to at least prevent CodePush from crashing the app when this happens.

@erandagan
Copy link

Seeing this on a production app as well. As suggested before, CodePush should probably fallback to the original bundle rather than crashing.

@jchirik
Copy link

jchirik commented Nov 30, 2018

Im getting this as well. please fix!

@Victorams
Copy link

Also happening here, however it seems to only occur in a specific device (Twist S520).

Positivo Twist (S520), Android 6.0
java.lang.RuntimeException: 
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2583)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2665)
  at android.app.ActivityThread.-wrap11 (ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1499)
  at android.os.Handler.dispatchMessage (Handler.java:111)
  at android.os.Looper.loop (Looper.java:207)
  at android.app.ActivityThread.main (ActivityThread.java:5765)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:789)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:679)
Caused by: com.microsoft.codepush.react.CodePushMalformedDataException: 
  at com.microsoft.codepush.react.CodePushUtils.getJsonObjectFromFile (CodePushUtils.java:198)
  at com.microsoft.codepush.react.CodePushUpdateManager.getCurrentPackageInfo (CodePushUpdateManager.java:55)
  at com.microsoft.codepush.react.CodePushUpdateManager.getCurrentPackageHash (CodePushUpdateManager.java:105)
  at com.microsoft.codepush.react.CodePushUpdateManager.getCurrentPackage (CodePushUpdateManager.java:115)
  at com.microsoft.codepush.react.CodePush.initializeUpdateAfterRestart (CodePush.java:254)
  at com.microsoft.codepush.react.CodePush.<init> (CodePush.java:82)
  at com.educarebox.app.MainApplication$1.getPackages (MainApplication.java:47)
  at com.facebook.react.ReactNativeHost.createReactInstanceManager (ReactNativeHost.java:81)
  at com.facebook.react.ReactNativeHost.getReactInstanceManager (ReactNativeHost.java:45)
  at com.facebook.react.ReactActivityDelegate.loadApp (ReactActivityDelegate.java:88)
  at com.facebook.react.ReactActivityDelegate.onCreate (ReactActivityDelegate.java:77)
  at com.facebook.react.ReactActivity.onCreate (ReactActivity.java:54)
  at android.app.Activity.performCreate (Activity.java:6301)
  at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1113)
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2530)
Caused by: org.json.JSONException: 
  at org.json.JSONTokener.syntaxError (JSONTokener.java:449)
  at org.json.JSONTokener.nextValue (JSONTokener.java:97)
  at org.json.JSONObject.<init> (JSONObject.java:156)
  at org.json.JSONObject.<init> (JSONObject.java:173)
  at com.microsoft.codepush.react.CodePushUtils.getJsonObjectFromFile (CodePushUtils.java:195)

@tbergquist-godaddy
Copy link

We also see this on Samsung Galaxy S9 and Sony Xperia X compact

@sridhard
Copy link

sridhard commented Mar 4, 2019

@yuri-kulikov any update on this issue...approximately 5% of users face this issue

@eggli
Copy link

eggli commented Mar 5, 2019

This really bugs people here, which make CodePush is unusable on any production environment, yet the migration to AppCenter already took one year and we haven't seen any glance of a trace of CodePush being migrated, looks like CodePush has been overlooked for a while.

Anyway, we've made a workaround for this unrecoverable fatal error here, the whole idea is to mimic the behavior of CodePush.clearUpdates() and remove all corrupted files so you can create a CodePush instance safely later.

In your MainApplication.java or whever you manage ReactNativeInstance,

@Override
protected List<ReactPackage> getPackages() {

  CodePush codePush;

  try {
      codePush = new CodePush(BuildConfig.CODEPUSH_KEY, getApplicationContext(), BuildConfig.DEBUG);
  } catch (Exception e) {
      // Reset code push update files when update files corrupted.
      // The following code is a mimic of CodePush.clearUpdates()
      // Since we already has exception in CodePush constructor,
      // we breakdown the constructor here and clear all code push
      // related files step by step without read the corrupted file itself.
      Context mContext = getApplicationContext();
      CodePushUpdateManager mUpdateManager = new CodePushUpdateManager(mContext.getFilesDir().getAbsolutePath());
      SettingsManager mSettingsManager = new SettingsManager(mContext);
      mUpdateManager.clearUpdates();
      mSettingsManager.removeFailedUpdates();
      mSettingsManager.removePendingUpdate();
      // After code push update files being removed, we can build a new code push instance safely
      codePush = new CodePush(BuildConfig.CODEPUSH_KEY, getApplicationContext(), BuildConfig.DEBUG);      
  }  
  return Arrays.<ReactPackage>asList(      
    codePush
    //...your other react native packages
  );
}

If you are a careful person, you might need a way to reproduce this exception, the easiest way to do this is upload a 0 bytes codepush.json into /data/data/<your app package name>/files/CodePush via Android Studio or adb on a CodePushed device and you will see this crash when you launch that app, once you applied the workaround above, the corrupted file shall be removed after launch and the whole CodePush update flow will be triggered again since all file has been removed.

@yuri-kulikov
Copy link
Contributor

Hi @eggli,
Thanks for the workaround, we appreciate it!

We'll try to reproduce it as you recommended and try to create a workaround in our package until we find out why codepush.json can become empty.

@sridhard
Copy link

sridhard commented Mar 5, 2019

@eggli thanks for the workaround. We will try this solution

@eggli
Copy link

eggli commented Mar 7, 2019

Hi @eggli,
Thanks for the workaround, we appreciate it!

We'll try to reproduce it as you recommended and try to create a workaround in our package until we find out why codepush.json can become empty.

I've checked codes that read/writes codepush.json, basically, I don't see anything wrong there, but in the world of Android, there're tons of hardware and OS pitfalls everywhere, in a summary, never trust your device, we are seeing this exception on some decent device like Samsung Galaxy S8+ aswell, it's very hard to figure out what's the root cause, yet we can make an assumption that users might kill the app during the writing process, it's a very common user behavior since people DO wrongly opened the app and killed it right away and the codepush.json might become empty.

Yet personally I've reproduced this empty file situation sometimes with this method, but it's not 100% reproducible.

@yuri-kulikov yuri-kulikov self-assigned this Mar 7, 2019
@yuri-kulikov
Copy link
Contributor

@eggli, thanks for sharing this information with us. I tried to reproduce this bug but wasn't lucky enough.

Work on a fix is in progress.

@yuri-kulikov
Copy link
Contributor

Hi everyone!
We've fixed the issue in the new version of react-native-code-push (5.6.0).

I'll close the issue for now, but feel free to ask any questions or reopen this issue if needed!

@AppKidd
Copy link

AppKidd commented May 7, 2021

Still seeing this in production on version in 6.4.1:

org.json.JSONException: End of input at character 0 of 
    at org.json.JSONTokener.syntaxError(JSONTokener.java:460)
    at org.json.JSONTokener.nextValue(JSONTokener.java:101)
    at org.json.JSONObject.<init>(JSONObject.java:164)
    at org.json.JSONObject.<init>(JSONObject.java:181)
    at com.microsoft.codepush.react.k.a
    at com.microsoft.codepush.react.h.b
    at com.microsoft.codepush.react.CodePushNativeModule$c.a
    at com.microsoft.codepush.react.CodePushNativeModule$c.doInBackground
    at android.os.AsyncTask$3.call(AsyncTask.java:378)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:919)
com.microsoft.codepush.react.d: Unable to parse contents of /data/user/0/com.org.app/files/CodePush/042f51b124e94983fff57fda5d4b5d7f912c63ab1079f5c38f0fe10ac6fcdde3/app.json, the file may be corrupted.
    at com.microsoft.codepush.react.k.a
    at com.microsoft.codepush.react.h.b
    at com.microsoft.codepush.react.CodePushNativeModule$c.a
    at com.microsoft.codepush.react.CodePushNativeModule$c.doInBackground
    at android.os.AsyncTask$3.call(AsyncTask.java:378)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:919)
java.lang.RuntimeException: An error occurred while executing doInBackground()
    at android.os.AsyncTask$4.done(AsyncTask.java:399)
    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
    at java.util.concurrent.FutureTask.run(FutureTask.java:271)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:919)

@sanjeevyadavIT
Copy link

Still seeing this in production on version 7.0.1

Fatal Exception: com.microsoft.codepush.react.d
Unable to parse contents of /data/user/0/in.example.tech/files/CodePush/codepush.json, the file may be corrupted.
com.microsoft.codepush.react.CodePushUtils.getJsonObjectFromFile
Fatal Exception: com.microsoft.codepush.react.d: Unable to parse contents of /data/user/0/in.example.tech/files/CodePush/codepush.json, the file may be corrupted.
       at com.microsoft.codepush.react.CodePushUtils.getJsonObjectFromFile(CodePushUtils.java:200)
       at com.microsoft.codepush.react.CodePushUpdateManager.getCurrentPackageInfo(CodePushUpdateManager.java:59)
       at com.microsoft.codepush.react.CodePushUpdateManager.getCurrentPackageHash(CodePushUpdateManager.java:109)
       at com.microsoft.codepush.react.CodePushUpdateManager.getCurrentPackage(CodePushUpdateManager.java:119)
       at com.microsoft.codepush.react.CodePush.initializeUpdateAfterRestart(CodePush.java:298)
       at com.microsoft.codepush.react.CodePush.<init>(CodePush.java:88)
       at in.example.tech.di.modules.ReactNativeModule$getReactNativeHost$1.getPackages(ReactNativeModule.java:70)
       at com.facebook.react.ReactNativeHost.createReactInstanceManager(ReactNativeHost.java:77)
       at com.facebook.react.ReactNativeHost.getReactInstanceManager(ReactNativeHost.java:39)
       at tech.library.react.ReactUtils.createReactContextInBackground(ReactUtils.java:42)
       at tech.library.react.ReactUtils$createReactContextInBackground$1.invokeSuspend(ReactUtils.java:11)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:33)
       at kotlinx.coroutines.internal.ScopeCoroutine.afterResume(ScopeCoroutine.java:33)
       at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.java:102)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:46)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.java:106)
       at android.os.Handler.handleCallback(Handler.java:873)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:201)
       at android.app.ActivityThread.main(ActivityThread.java:6861)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by org.json.JSONException: End of input at character 0 of 
       at org.json.JSONTokener.syntaxError(JSONTokener.java:449)
       at org.json.JSONTokener.nextValue(JSONTokener.java:97)
       at org.json.JSONObject.<init>(JSONObject.java:159)
       at org.json.JSONObject.<init>(JSONObject.java:176)
       at com.microsoft.codepush.react.CodePushUtils.getJsonObjectFromFile(CodePushUtils.java:197)
       at com.microsoft.codepush.react.CodePushUpdateManager.getCurrentPackageInfo(CodePushUpdateManager.java:59)
       at com.microsoft.codepush.react.CodePushUpdateManager.getCurrentPackageHash(CodePushUpdateManager.java:109)
       at com.microsoft.codepush.react.CodePushUpdateManager.getCurrentPackage(CodePushUpdateManager.java:119)
       at com.microsoft.codepush.react.CodePush.initializeUpdateAfterRestart(CodePush.java:298)
       at com.microsoft.codepush.react.CodePush.<init>(CodePush.java:88)
       at in.example.tech.di.modules.ReactNativeModule$getReactNativeHost$1.getPackages(ReactNativeModule.java:70)
       at com.facebook.react.ReactNativeHost.createReactInstanceManager(ReactNativeHost.java:77)
       at com.facebook.react.ReactNativeHost.getReactInstanceManager(ReactNativeHost.java:39)
       at example.library.react.ReactUtils.createReactContextInBackground(ReactUtils.java:42)
       at example.library.react.ReactUtils$createReactContextInBackground$1.invokeSuspend(ReactUtils.java:11)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:33)
       at kotlinx.coroutines.internal.ScopeCoroutine.afterResume(ScopeCoroutine.java:33)
       at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.java:102)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:46)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.java:106)
       at android.os.Handler.handleCallback(Handler.java:873)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:201)
       at android.app.ActivityThread.main(ActivityThread.java:6861)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

@ribamarsantos
Copy link

Hey Folks,

I saw this was closed. Could someone point me to where the resolution is? As I could see the last post mentioned that the error still persists and I just wanted to flag that this is happening for us too.

Screen Shot 2022-03-03 at 9 43 18 AM

Screen Shot 2022-03-03 at 9 44 00 AM

Using version 7.0.4 of Codepush
RN - 0.64.2

@HarshitMadhav
Copy link

this issue still exists, currently we are running on v7.0.4 of codepush

@MAKARD
Copy link
Contributor

MAKARD commented Feb 1, 2024

still there on v8.1.0

@hansol-yang
Copy link

v8.2.1 also..

@DmitriyKirakosyan
Copy link
Contributor

This issue was fixed in v8.2.2 (#2668).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests