Cordova - After putting Android app in background mode for a few hours, CB lite is unresponsive

Hey everyone,

As stated in the subject line, my Cordova app running on Android is experiencing issues with connecting to CB lite after the app has been put in background mode for a number of hours. This is happening to all of my Android users and me.

When I look at the network log of the traffic of the app after resumption, all CB lite calls are pending.

I need urgent help on this as it’s killing user adoption on Android. I’m not experiencing this issue on IOS.

Is there a inactivity timeout setting I can adjust?

To all the Cordova developers for Android, does anyone have success with their app running in the background and reconnecting to CB lite on resumption?

Can someone from Couchbase help me out with this issue?

I tried using

cblite.getURL()

on resume, thinking that the username/password might have expired.

But I got the same username/password with the call.

@agillette,

So you in the CBL running and not responding?
or
CBL not running?

So it looks like CBL is running because I’m getting a response back from cblite.getURL().

But when trying to connect to the app database, the API call stays in “pending” mode, no response.

Is the background mode getting triggered in code or when the user leaves the app?

cblite.getURL() is usually called when the app is initialized to retrieve the listener URL. Where did you call cblite.getURL() after the app got backgrounded?

With regards to the pending mode for the API calls, do you see the pending state in the Chrome debugger console?

James

@jamiltz ,

Background mode is triggered when the user leaves the app.

This morning I added the following code:

 function onResume() {
    if (device.platform === 'Android') {
      cblite.getURL(function (error, url) {
    if (error) {
      console.log('CB Initilization error ' + JSON.stringify(error));
      reject('CB Initilization error', error);
    }

    console.log('couchbase url ', url);
  });
    }
  }

  document.addEventListener("resume", onResume, false);

The console logs the CBL url, no problem with that. And the username/password is the same as when the app starts for the first time.

But when I do a GET call with the database name, the call stays in pending mode.

I’m monitoring the API calls in Chrome debugger.

I did a test with the Todo-lite example and the same issue is occurring when I return to the app after 30 minutes.

This is a big problem as it renders CBL-based apps useless.

@jamiltz ,

Let me clarify “user leaves the app”, the app is background mode and is paused. If the app is shutdown and restarted, everything with CBL is fine. But there’s no way through code to do a full shutdown and restart with Cordova.

Hi @agillette,

I have one request to verity.
From your comment, once the app resumed, the app can obtain URL of CBL REST API endpoint. Can you try to access its URL from Android browser or to access from out-side of Android device/emulator by browser or curl command?
If Http server can response, JavaScript or WebView which is used by Cordova/PhoneGap has issue.
If Http server can NOT response, Couchbase Lite Java Listener has issue or enter bad state.

But when trying to connect to the app database, the API call stays in “pending” mode, no response.

Could you please share the details of “pending” mode? If you wait for a while, do you receive timeout or some error response?

We’d like to reproduce this issue, could you please provide CBL for PhoneGap version?

Thanks!

Hi @hideki,

I’m pretty sure that the WebView is not the issue. On resume, cblite.getURL(function (error, url) is working. But if I make a REST call to my database, the calls are pending.

I’m going to modify my to make a call to sync gateway on resume. If it responds and the REST call to the local db doesn’t, we’ll know that the WebView is not the culprit.

I’ll let you know in 30 mins.

You can use the reference TODO-LIst app to try to reproduce the issue.

BTW - I’m using 1.2.1.

@hideki,

There’s a code error in the test that I just did. I’ll have to try again tomorrow morning.

@hideki,

I just ran a test where on resume my code is making two calls, one to the local db and one to sync gateway. The sync gateway responded with 200, where as the local db is still in “pending” state. This proves to me that the problem is with CBL and not the WebView.

@hideki: It could be that the OS has closed the TCP listener socket. (For comparison, iOS does this when an app has been backgrounded too long and/or the device locks.)

Hi @agillette,

Thank you very much for sharing additional information.

To track this issue, I created the ticket in github.

Thanks,
Hideki

Thanks @hideki,

Please keep me posted. I’m planning to submit my app into both Apple and Google app stores in two weeks.

For future reference, if something is definitely going wrong (as in this case), it’s more efficient to report it by filing an issue on Github, rather than posting a thread here.

Will do @jens. Thanks for the suggestion.

But in this case it’s a little challenging to determine which product has the issue. I’m wasn’t sure if it’s phonegap plugin, the the java library, or something else.