React-native-code-push: An error occurred while executing doInBackground()

Created on 16 Apr 2018  路  22Comments  路  Source: microsoft/react-native-code-push

I've been receiving:

java.lang.RuntimeException An error occurred while executing doInBackground() 
    AsyncTask.java:309 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:1113 java.util.concurrent.ThreadPoolExecutor.runWorker
    ThreadPoolExecutor.java:588 java.util.concurrent.ThreadPoolExecutor$Worker.run
    Thread.java:818 java.lang.Thread.run


Caused by: com.microsoft.codepush.react.CodePushUnknownException Error closing IO resources. 
    FileUtils.java:176 com.microsoft.codepush.react.FileUtils.unzipFile
    CodePushUpdateManager.java:218 com.microsoft.codepush.react.CodePushUpdateManager.downloadPackage
    CodePushNativeModule.java:210 com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground
    CodePushNativeModule.java:204 com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground
    AsyncTask.java:295 android.os.AsyncTask$2.call
    FutureTask.java:237 java.util.concurrent.FutureTask.run
    ThreadPoolExecutor.java:1113 java.util.concurrent.ThreadPoolExecutor.runWorker
    ThreadPoolExecutor.java:588 java.util.concurrent.ThreadPoolExecutor$Worker.run
    Thread.java:818 java.lang.Thread.run


Caused by: java.util.zip.ZipException invalid stored block lengths 
    ZipInputStream.java:360 java.util.zip.ZipInputStream.read
    Streams.java:159 libcore.io.Streams.skipByReading
    InflaterInputStream.java:213 java.util.zip.InflaterInputStream.skip
    Streams.java:133 libcore.io.Streams.skipAll
    ZipInputStream.java:144 java.util.zip.ZipInputStream.closeEntry
    ZipInputStream.java:115 java.util.zip.ZipInputStream.close
    FileUtils.java:172 com.microsoft.codepush.react.FileUtils.unzipFile
    CodePushUpdateManager.java:218 com.microsoft.codepush.react.CodePushUpdateManager.downloadPackage
    CodePushNativeModule.java:210 com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground
    CodePushNativeModule.java:204 com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground
    AsyncTask.java:295 android.os.AsyncTask$2.call
    FutureTask.java:237 java.util.concurrent.FutureTask.run
    ThreadPoolExecutor.java:1113 java.util.concurrent.ThreadPoolExecutor.runWorker
    ThreadPoolExecutor.java:588 java.util.concurrent.ThreadPoolExecutor$Worker.run
    Thread.java:818 java.lang.Thread.run

in production Android devices > version 6.

Could that be a duplicate of https://github.com/Microsoft/react-native-code-push/issues/873 ?

fix-in-master

Most helpful comment

Howdy folks, just a quick update that we're are still looking at this. We are trying to reproduce it and make sure we understand it and weighting the pros and cons of possible solutions. My hope is we have something sorted next week, but I can't make any promises. I am new to the project and have some catching up to do, so I apologize that this also is making things a little slower.

All 22 comments

Hi @SudoPlz
Yes it can. Have you tried fix your issue as mentioned in #873 ?

I'm going to try and post back.

Here's my code:

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    // We need this in order to fix https://github.com/Microsoft/react-native-code-push/issues/1257#issuecomment-381944498
    CodePush.getJSBundleFile(); // we must run this before setLayout takes place
    // a.k.a before super.onCreate

    super.onCreate(savedInstanceState);
}

Unfortunately since I'm using react-native-navigation I don't have fine control over when setContentView get's called, do you think calling getJSBundleFile before super.onCreate() will be ok @iTOYS ?

ok, so I can't do that because I receive:

       java.lang.RuntimeException: Unable to start activity ComponentInfo{com.testapp.app.android/com.testapp.app.android.MainActivity}: com.microsoft.codepush.react.CodePushNotInitializedException: A CodePush instance has not been created yet. Have you added it to your app's list of ReactPackages?
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
              at android.app.ActivityThread.-wrap12(ActivityThread.java)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:154)
              at android.app.ActivityThread.main(ActivityThread.java:6119)
              at java.lang.reflect.Method.invoke(Native Method)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
           Caused by: com.microsoft.codepush.react.CodePushNotInitializedException: A CodePush instance has not been created yet. Have you added it to your app's list of ReactPackages?
              at com.microsoft.codepush.react.CodePush.getJSBundleFile(CodePush.java:186)
              at com.microsoft.codepush.react.CodePush.getJSBundleFile(CodePush.java:181)
              at com.testapp.app.android.MainActivity.onCreate(MainActivity.java:25)
              at android.app.Activity.performCreate(Activity.java:6679)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)聽
              at android.app.ActivityThread.-wrap12(ActivityThread.java)聽
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)聽
              at android.os.Handler.dispatchMessage(Handler.java:102)聽
              at android.os.Looper.loop(Looper.java:154)聽
              at android.app.ActivityThread.main(ActivityThread.java:6119)聽
              at java.lang.reflect.Method.invoke(Native Method)聽
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)聽
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)聽

:/

Is there any other place I can run getJSBundleFile ?
At the moment I'm running it in MainApplication.java like so:

@Override
    public String getJSBundleFile() {
        return CodePush.getJSBundleFile();
    }

Ok so back to ground zero. No idea what to try.

@SudoPlz any success resolving this issue, I am facing same in app with react-native-navigation

Nope, no success yet @manjeetwadi

Facing the same issue. +1

Hi all,

We are working on it.

Awesome, thanks for the update @alexandergoncharov we'll be patiently standing by.

:)

+1

Hi @SudoPlz, @manjeetwadi, @anuraginwadi, @shashankwadi,,

Could you please provide some part of your code which can help me to reproduce this issue?

Thanks,
Alexander

Unfortunately I was not able to reproduce that at will. We only received that on our crash-reporter (bugsnag).

Maybe someone else knows more?

similar thing happened for us too

Howdy folks, just a quick update that we're are still looking at this. We are trying to reproduce it and make sure we understand it and weighting the pros and cons of possible solutions. My hope is we have something sorted next week, but I can't make any promises. I am new to the project and have some catching up to do, so I apologize that this also is making things a little slower.

Hi all,
Sorry for long delay.

Seems this reason of this Error in zipStream.close() method but no info how is it possible to reproduce exactly it.
Anyway, I added Error manually in this place and this Error crash user app like this:
image
App shouldn鈥檛 be crashed if we got Exception from our plugin because our broken plugin should not affect work of application. So, I think that we should catch CodePushExceptions and just log it without throwing.

Found approaches for this:

  1. Made wrapper for CodePushNativeModule with overriding all public method with Try-catch.
    Pros:

    • easy fast fix.

      Cons:

    • Not good approach because if other developers will add new methods then they should add new method in wrapper.

  1. Use https://github.com/cglib/cglib for working with Proxy Java class. We can鈥檛 use Proxy approach without this lib in our case.
    Pros:

    • Minimal changes for existing code.

      Cons:

    • Adding external lib.

I think that first approach is prefer in our case because it isn鈥檛 expected new methods in functional and issue is not so critical for adding external lib.
Anyway, I think we should continue investigate issue with closing stream but at first, I think, we should fix issue with closing app if we got error from CodePush.

@half-ogre , Could you please share your thoughts about approaches?

Thanks,
Alexander

I generally favor the first approach. @max-mironov and @sergey-akhalkov, do you have any thoughts on this?

Hi @half-ogre,
we discussed the issue with @max.mironov and @sergey.akhalkov and our thought is also that plugin shouldn鈥檛 crash the app, but we suggest just to add catching and logging of CodePushUnknownException.
There is no point to implementing something more complex here as brownfield-apps-dev branch already contains similar mechanism https://github.com/Microsoft/react-native-code-push/blob/brownfield-apps-dev/android/app/src/main/java/com/microsoft/codepush/common/utils/CodePushLogUtils.java#L57

Yeah, just catching errors will be more easy and faster. So, we can implement catching errors as hot fix until we finish work on _brownfield_.
@NickToropov, @half-ogre What do you think about it?

Even better. Let's move forward with that. Thanks!

Hi all,

I made PR for preventing crashes of app by catching Exceptions. Could please someone test it?
https://github.com/Microsoft/react-native-code-push/pull/1286

Thanks,
Alexander

Hi all,
Changes are published in 5.3.4 version: https://github.com/Microsoft/react-native-code-push/releases/tag/v5.3.4

I'll close this issue as it was resolved by hot fix but please feel free to reopen it if you have any questions.

Thanks,
Alexander

Thanks @alexandergoncharov

Was this page helpful?
0 / 5 - 0 ratings

Related issues

osdnk picture osdnk  路  3Comments

chrisjrex picture chrisjrex  路  4Comments

ACCTFORGH picture ACCTFORGH  路  3Comments

Phredward picture Phredward  路  3Comments

djw27 picture djw27  路  3Comments