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

any reports of hangs with [email protected] and later ? #86

Closed
jhjulkun opened this issue Nov 18, 2019 · 9 comments
Closed

any reports of hangs with [email protected] and later ? #86

jhjulkun opened this issue Nov 18, 2019 · 9 comments

Comments

@jhjulkun
Copy link

jhjulkun commented Nov 18, 2019

Thanks for a great plugin!

I have been trying to create a shorter testcase (using cordova-sqlite-ext-bootstrap-starter-app), but no luck so far.

But just wondering if you have any ideas why the first transaction on an open database simply just seems to hang (on later versions, and seems to happen more frequently in Android10).
On my Pixel(1) my app only works every fourth time or so.
The iOS version does not seem to have this issue.

I can't for sure say when it started happening, I'll try figuring that out next (I'm using a non published plugin, and the cordova --noregistry or --nofetch seems to be ignored so its non
trivial to try different releases)

But I know plugin worked well in:
[email protected] and cordova-sqlite-ext 0.10.0

In the (non complete) codesnippet below, "rowData" is never printed when it does not work.

Thanks!

  db.transaction(function(tx) {
        var sql = "select version from settings";
        console.log(sql);

        tx.executeSql(sql, [], function(tx, res) {
            //            console.log("res.rows.length: " + res.rows.length);                                                                                                                                                                                                                                                                                  
            for (var i = 0; i < res.rows.length; i++) {
                console.log("rowData " + res.rows.item(i).version);
...

@TylerHamm
Copy link

I am by far no master at this (I have my own issue opened lol) but I see no one is trying to help you, so maybe I could ask some questions they might. I will be using mostly knowledge from my week of trying to fix my own issue so apologies lol.

Are any errors thrown or does it just hang as you stated?
Are you waiting until the device is ready by using platform.ready()? I have seen a lot of suggestions with hanging issues come from that.
Are you using “BEGIN TRANSACTION” and “COMMIT” as book ends? I personally use the sqlexecute command instead of transaction but I see this thrown around as well.

@jhjulkun
Copy link
Author

Thanks for the help.
No errors thrown, it just hangs (sometimes).
Frequency of hang seems to be related to type of device (which seems to suggest a "race" condition).
Due to dependency issues from plugins/cordova tools and google play services its very
difficult to build using different versions of cordova, but testing with old apk files on same hang prone device always seems to work.

I use sqlexecute

@brody4hire
Copy link
Owner

The one thing I can think of is to be extra careful not to do anything with this plugin before you receive the deviceready event. This is a very unfortunate characteristic of Cordova.

Similar issue reported in storesafe/cordova-sqlite-storage#900, as a cross-reference.

@jhjulkun
Copy link
Author

jhjulkun commented Dec 3, 2019

Definitely waiting on deviceready...

I have unfortunately not been able to narrow it down (due to various build issues), but using an old APK on a device that has issues always seems to work, so I believe something has changed.
I tried using my huge (~25Mb .db file) using the https://github.com/brodybits/cordova-sqlite-ext-bootstrap-starter-app, but it seems to work, so not sure.
Unfortunately I have a lot of plugins, so its really hard to narrow down
cordova-android-play-services-gradle-release 4.0.0 "cordova-android-play-services-gradle-release"
cordova-fabric-plugin 1.1.14-dev "cordova-fabric-plugin"
cordova-plugin-admobpro 2.49.0 "AdMob Plugin Pro"
cordova-plugin-android-permissions 1.0.2 "Permissions"
cordova-plugin-battery-status 2.0.3 "Battery"
cordova-plugin-buildinfo 4.0.0 "BuildInfo"
cordova-plugin-device 2.0.3 "Device"
cordova-plugin-extension 1.5.4 "Cordova Plugin Extension"
cordova-plugin-file 6.0.2 "File"
cordova-plugin-file-transfer 1.7.1 "File Transfer"
cordova-plugin-geolocation 4.0.2 "Geolocation"
cordova-plugin-google-analytics 1.8.6 "Google Universal Analytics Plugin"
cordova-plugin-inapppurchase 1.1.0 "In App Purchase"
cordova-plugin-insomnia 4.3.0 "Insomnia (prevent screen sleep)"
cordova-plugin-network-information 2.0.2 "Network Information"
cordova-plugin-whitelist 1.3.4 "Whitelist"
cordova-plugin-zip 3.1.0 "cordova-plugin-zip"
cordova-sqlite-ext 3.0.1 "Cordova sqlite storage plugin with extra features"
sqli-cordova-disk-space-plugin 1.0.2 "DiskSpacePlugin"

@brody4hire
Copy link
Owner

Interesting, thanks @jhjulkun. So at this point, we have one app that does work with your ~25MB db file and another app that is affected by some kind of an issue. I would now recommend you try out a couple more ideas:

  • upon startup, try a very dumb and simple statement such as SELECT 1, and try it on an empty database
  • try removing some things from your app until you get a better idea what may be leading to the issue

Seems to be basically try one thing at a time to figure out what does and does not work properly.

I suspect it could help some others if you can figure this one out.

@jhjulkun
Copy link
Author

jhjulkun commented Dec 4, 2019

Interesting: so added the sample.db from the starter and running the showFirst() as the first query (and only when it has completed I run my normal code)

Looking at the log, the plugin claims the sample.db is opened:
12-04 10:32:25.907 18669 18773 V info : Open sqlite db: /data/user/0/app/files/files/sample.db
12-04 10:32:25.987 18669 18669 D SystemWebChromeClient: file:///android_asset/www/js/SQLitePlugin.js: Line 49 : DB opened: sample.db

But then the app then crashes with:
12-04 10:32:26.015 18669 18773 W System.err: java.sql.SQLException: sqlite3_prepare_v2 failure: no such table: SampleTable

Whats interesting is that it does not crash every time, but say maybe every 2nd time ?

Almost sounds like file I/O has not been flushed before cordova starts running ?
Has there been any changes with regard to that ?

I know for sure I have not seen that exact message (before the hack), but maybe I don't catch all errors ?

@jhjulkun
Copy link
Author

jhjulkun commented Jul 20, 2020

Spent some more time on this, and it seems to be that ActivityManager kills (something in the app) every so often on launch. I googled for a workaround, but could not find anything that helps.
It still happens on @android9.0.0 release (and old Pixel device running Android 10).
Also tried removing all non necessary plugins, at some point it always becomes frozen.

So in short: I believe that since the plugin runs as a background thread, and when it consumes too much power then ActivityManager kills it.
Are there some flags in cordova that can be set to prevent that ?
Or run in the the foreground ?
Note that the app doesn't die: but since the DB is killed it waits for the query to finish.

In the ADB log below the app runs on the 2nd launch, and the DB thread is killed on the 1st attempt.

ActivityManager: Start proc 3664:zzz.yyy.xxx/u0a322 for activity {zzz.yyy.xxx/zzz.yyy.xxx.MainActivity}
ActivityManager: Start proc 3737:com.google.android.webview:sandboxed_process0:org.chromium.content.app.SandboxedProcessService0:0/u0i175 for {zzz.yyy.xxx/org.chromium.content.app.SandboxedProcessService0:0}

ActivityManager: Killing 3664:zzz.yyy.xxx/u0a322 (adj 905): remove task <<< killed!!

ActivityManager: Scheduling restart of crashed service zzz.yyy.xxx/org.chromium.content.app.SandboxedProcessService0:0 in 1000ms
ActivityManager: Start proc 3826:zzz.yyy.xxx/u0a322 for activity {zzz.yyy.xxx/zzz.yyy.xxx.MainActivity}
ActivityManager: Start proc 3858:com.google.android.webview:sandboxed_process0:org.chromium.content.app.SandboxedProcessService0:0/u0i176 for {zzz.yyy.xxx/org.chromium.content.app.SandboxedProcessService0:0}
(app keeps running normally)
Bummed I didn't catch this message before..

@brody4hire
Copy link
Owner

Without a reproducible example there is not so much that I or anyone else can do to help you from here, closing now.

@jhjulkun
Copy link
Author

jhjulkun commented Jul 20, 2020

Now that I have a better idea of what causes the hang, maybe I can make a testcase ?
I think you just need a massive database file, and opening that will cause the database to be killed by ActivityManager.

Update: the ActivityManager lead was totally false, your starter app kept working...

Finally realized index.html loaded this manually, but the starter doesn't...
The plugin file was from oct 2015 (and many diffs to the current one!)
I'm surprised it has worked at all, and why the iOS version never had any issues ?

<script src="js/SQLitePlugin.js"></script>

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

3 participants