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

Callback issue Android #325

Closed
dominichadfield opened this issue Nov 20, 2018 · 6 comments
Closed

Callback issue Android #325

dominichadfield opened this issue Nov 20, 2018 · 6 comments
Labels
🤖 android Related to android 🙏 help wanted Extra attention is needed

Comments

@dominichadfield
Copy link

dominichadfield commented Nov 20, 2018

Version of react-native-iap

"react-native": "0.55.2"
"react-native-iap": "^2.3.19"

Platforms you faced the error (IOS or Android or both?)

Android

Expected behavior

No crash

Actual behavior

Fatal crash

Stacktrace:

java.lang.RuntimeException Illegal callback invocation from native module. This callback type only permits a single invocation from native code. 
    CallbackImpl.java:28 com.facebook.react.bridge.CallbackImpl.invoke
    PromiseImpl.java:30 com.facebook.react.bridge.PromiseImpl.resolve
    RNIapModule.java:155 com.dooboolab.RNIap.RNIapModule$4.run
    RNIapModule.java:124 com.dooboolab.RNIap.RNIapModule$3.onBillingSetupFinished
    BillingClientImpl.java:903 com.android.billingclient.api.BillingClientImpl$BillingServiceConnection.onServiceConnected
    LoadedApk.java:1835 android.app.LoadedApk$ServiceDispatcher.doConnected
    LoadedApk.java:1864 android.app.LoadedApk$ServiceDispatcher$RunConnection.run
    Handler.java:809 android.os.Handler.handleCallback
    Handler.java:102 android.os.Handler.dispatchMessage
    Looper.java:166 android.os.Looper.loop
    ActivityThread.java:7377 android.app.ActivityThread.main
    Method.java:-2 java.lang.reflect.Method.invoke
    RuntimeInit.java:469 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run
    ZygoteInit.java:963 com.android.internal.os.ZygoteInit.main

Tested environment (Emulator? Real Device?)

Live

Steps to reproduce the behavior

Unable to reproduce, have many reports from live app before rollback on crashlytics and bugsnag. App is always in the background when crash occurs.

Code

Initialised on app start:

function* loadAvailableSubscriptions() {
  try {
    const productIds = yield select(getProductIds);
    const subscriptions = yield call(RNIap.getSubscriptions, productIds);
    yield put(setAvailableSubscriptions(subscriptions));
  } catch (error) {
    console.error('Error: loadAvailableSubscriptions', error);
    reportError({ error });
  }
}

export default function* initializeSubscription(): Saga<*> {
  try {
    yield call(RNIap.initConnection);
    yield call(loadAvailableSubscriptions);
    yield put(subscriptionInitialized());
  } catch (error) {
    console.error('Error: initializeSubscription', error);
    reportError({ error });
  }
}

Calling every time app state changes:

export function* appStateChangeWorker(nextAppState: AppState): Saga<*> {
  if (nextAppState === 'active') {
    yield call(RNIap.initConnection);
  } else if (nextAppState === 'background' || nextAppState === 'inactive') {
    yield call(RNIap.endConnection);
  }
}
@Pingou
Copy link

Pingou commented Nov 21, 2018

Same problem.

@hyochan hyochan added 🙏 help wanted Extra attention is needed 🤖 android Related to android labels Nov 22, 2018
@hyochan
Copy link
Member

hyochan commented Nov 22, 2018

I think to figure out your case, you need to put log before each function call and try to find out where it is invoking methods. There may be some situations in your code which are not thread safe.

@pyankoff
Copy link

pyankoff commented Dec 2, 2018

Having the same problem with live version of the app :(
Trying to make sure I init and close connection just once by counting invocations. Anything else I can try for thread safety?

@dominichadfield
Copy link
Author

dominichadfield commented Dec 3, 2018

We ended up forking the library and wrapping with a try catch to prevent fatal. Not a long term solution but stops crashes.

try {
           if (responseCode == BillingClient.BillingResponse.OK) {
            Log.d(TAG, "billing client ready");
               callback.run();
           } else {
            rejectPromiseWithBillingError(promise, responseCode);
          }
         } catch (Exception e) {
          Bugsnag.notify(e);
        }

@pyankoff
Copy link

pyankoff commented Dec 6, 2018

@domhadfield thanks for suggestion, will do that too as a temporary fix. I'll also try closing connection on switching to background.

I've managed to crash the app in background by force closing Play Store app while the IAP connection is open. Here is the comment I've got this idea from: android/play-billing-samples#45 (comment)

I'm not sure how many users might actually close Play Store, but maybe there are similar circumstances causing the crash? I'm getting like ~1% sessions crash rate from this, which is quite high. @dooboolab can this help somehow?

@hyochan
Copy link
Member

hyochan commented Dec 16, 2018

Related #315. We will keep this issue up there.

@hyochan hyochan closed this as completed Dec 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖 android Related to android 🙏 help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants