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

Crashing on multiple geofencing adds while in a geofence #113

Closed
timwright35 opened this issue Jan 18, 2016 · 28 comments
Closed

Crashing on multiple geofencing adds while in a geofence #113

timwright35 opened this issue Jan 18, 2016 · 28 comments

Comments

@timwright35
Copy link

I am having the app crash when multiple geofences (6+) are added using addOrUpdate function while I am currently in a geofence. I am using plugin version 0.5.0.

01-18 14:15:38.899: E/AndroidRuntime(16894): FATAL EXCEPTION: IntentService[ReceiveTransitionsIntentService]
01-18 14:15:38.899: E/AndroidRuntime(16894): Process: com.app.geofenceTest, PID: 16894
01-18 14:15:38.899: E/AndroidRuntime(16894): java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed.
01-18 14:15:38.899: E/AndroidRuntime(16894):    at android.database.sqlite.SQLiteConnectionPool.throwIfClosedLocked(SQLiteConnectionPool.java:962)
01-18 14:15:38.899: E/AndroidRuntime(16894):    at android.database.sqlite.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java:599)
01-18 14:15:38.899: E/AndroidRuntime(16894):    at android.database.sqlite.SQLiteConnectionPool.acquireConnection(SQLiteConnectionPool.java:348)
01-18 14:15:38.899: E/AndroidRuntime(16894):    at android.database.sqlite.SQLiteSession.acquireConnection(SQLiteSession.java:894)
01-18 14:15:38.899: E/AndroidRuntime(16894):    at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:834)
01-18 14:15:38.899: E/AndroidRuntime(16894):    at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
01-18 14:15:38.899: E/AndroidRuntime(16894):    at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:143)
01-18 14:15:38.899: E/AndroidRuntime(16894):    at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:132)
01-18 14:15:38.899: E/AndroidRuntime(16894):    at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:219)
01-18 14:15:38.899: E/AndroidRuntime(16894):    at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:258)
01-18 14:15:38.899: E/AndroidRuntime(16894):    at com.cowbell.cordova.geofence.LocalStorage.getItem(LocalStorage.java:57)
01-18 14:15:38.899: E/AndroidRuntime(16894):    at com.cowbell.cordova.geofence.GeoNotificationStore.getGeoNotification(GeoNotificationStore.java:20)
01-18 14:15:38.899: E/AndroidRuntime(16894):    at com.cowbell.cordova.geofence.ReceiveTransitionsIntentService.onHandleIntent(ReceiveTransitionsIntentService.java:69)
01-18 14:15:38.899: E/AndroidRuntime(16894):    at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:66)
01-18 14:15:38.899: E/AndroidRuntime(16894):    at android.os.Handler.dispatchMessage(Handler.java:102)
01-18 14:15:38.899: E/AndroidRuntime(16894):    at android.os.Looper.loop(Looper.java:148)
01-18 14:15:38.899: E/AndroidRuntime(16894):    at android.os.HandlerThread.run(HandlerThread.java:61)
@bromeostasis
Copy link

@Tempus35 were you able to solve/figure this out? I'm receiving the same error when the app goes in the background for too long.

@timwright35
Copy link
Author

@bromeostasis are you using the iOS or Android code?

@bromeostasis
Copy link

@Tempus35 Android.

@bromeostasis
Copy link

@Tempus35 wow as I was typing this, I got the error again when initializing our app.

03-24 13:56:37.908: E/AndroidRuntime(11657): FATAL EXCEPTION: IntentService[ReceiveTransitionsIntentService]
03-24 13:56:37.908: E/AndroidRuntime(11657): Process: com.larky.chcu, PID: 11657
03-24 13:56:37.908: E/AndroidRuntime(11657): java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed.
03-24 13:56:37.908: E/AndroidRuntime(11657):    at android.database.sqlite.SQLiteConnectionPool.throwIfClosedLocked(SQLiteConnectionPool.java:962)
03-24 13:56:37.908: E/AndroidRuntime(11657):    at android.database.sqlite.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java:599)
03-24 13:56:37.908: E/AndroidRuntime(11657):    at android.database.sqlite.SQLiteConnectionPool.acquireConnection(SQLiteConnectionPool.java:348)
03-24 13:56:37.908: E/AndroidRuntime(11657):    at android.database.sqlite.SQLiteSession.acquireConnection(SQLiteSession.java:894)
03-24 13:56:37.908: E/AndroidRuntime(11657):    at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:834)
03-24 13:56:37.908: E/AndroidRuntime(11657):    at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
03-24 13:56:37.908: E/AndroidRuntime(11657):    at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:144)
03-24 13:56:37.908: E/AndroidRuntime(11657):    at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:133)
03-24 13:56:37.908: E/AndroidRuntime(11657):    at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:197)
03-24 13:56:37.908: E/AndroidRuntime(11657):    at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:237)
03-24 13:56:37.908: E/AndroidRuntime(11657):    at com.cowbell.cordova.geofence.LocalStorage.getItem(LocalStorage.java:57)
03-24 13:56:37.908: E/AndroidRuntime(11657):    at com.cowbell.cordova.geofence.GeoNotificationStore.getGeoNotification(GeoNotificationStore.java:20)
03-24 13:56:37.908: E/AndroidRuntime(11657):    at com.cowbell.cordova.geofence.ReceiveTransitionsIntentService.onHandleIntent(ReceiveTransitionsIntentService.java:69)
03-24 13:56:37.908: E/AndroidRuntime(11657):    at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
03-24 13:56:37.908: E/AndroidRuntime(11657):    at android.os.Handler.dispatchMessage(Handler.java:102)
03-24 13:56:37.908: E/AndroidRuntime(11657):    at android.os.Looper.loop(Looper.java:136)
03-24 13:56:37.908: E/AndroidRuntime(11657):    at android.os.HandlerThread.run(HandlerThread.java:61)

@timwright35
Copy link
Author

@bromeostasis So I am trying to remember how I fixed my issue. I know it has to do with the SQL connection being closed and so it errors. The function that errors is in the GeoNotificationStore when it tries to save to localstorage (ie in this case sqlite as localstorage).

It might have been fixed in the changes I made to GeoNotificationNotifier, see my PR #116. I change the way the intent is setup allow it to run in the background and open differently.

@bromeostasis
Copy link

@Tempus35 great, giving it a shot! It's been a fairly difficult issue to reproduce, but I'll try it and let you know how it goes.

@timwright35
Copy link
Author

@bromeostasis nah it is referring to a function I changed in another place, change that line back to .setAutoCancel(true) and try again.

@bromeostasis
Copy link

@Tempus35 hehe yeah I realized that and deleted my comment :D

I added the autocancel parameter to Notification.java and got the build to work.

Unfortunately, I'm still seeing the error as soon as I start adding fences! I only copied over the GeoNotificationNotifier.java code (plus the Notification.java fix). Do you recommend I grab the entire PR?

@timwright35
Copy link
Author

@bromeostasis nah, that PR was not fulling finished, I will look back through my last code I made and see if there was anything else that might have been a fix for that.

@bromeostasis
Copy link

@Tempus35 thanks so much, I really appreciate it!

@bromeostasis
Copy link

@Tempus35 by the way, this:

I got the error again when initializing our app

means that the issue also happens in the foreground. Just wanted to let you know since you mentioned

It might have been fixed in the changes I made to GeoNotificationNotifier, see my PR #116. I change the way the intent is setup allow it to run in the background and open differently.

@timwright35
Copy link
Author

@bromeostasis So one thing I read about while doing some quick research as well is that if you replace line 52 in LocalStorageDBHelper ( public static LocalStorageDBHelper getInstance(Context ctx) ) to

public static synchronized LocalStorageDBHelper getInstance(Context ctx)

See if that helps, while I continue to look around.

@bromeostasis
Copy link

@Tempus35 thanks! I actually rebuilt the GeoNotificationNotifier changes and haven't seen the error since. I'm thinking my dropbox may have had an old version so I didn't actually get the changes on my device.

I'm gonna leave those changes up for the evening to test it out. If I get the error again, I'll definitely try adding the synchronized keyword and ask for your help once more!

@timwright35
Copy link
Author

@bromeostasis Not a problem, I have had a couple issues with this plugin and more than happy to share what I found out.

@bromeostasis
Copy link

@Tempus35 cool, much appreciated! ✌️

@bromeostasis
Copy link

@Tempus35 unfortunately, I'm seeing more of this problem today on my Android 4 device (have yet to see it on Android 5 since Java changes).

It happens when I log into our app, which does subsequently add a lot of geofences, and I am definitely inside of one.

More verbose logs (locations/names removed) :

D/ConnectivityService(  750): handleInetConditionHoldEnd: net=1, condition=100, published condition=100
I/chromium(28058): [INFO:CONSOLE(212)] "Debug: geofencing - Insert is done", source: file:///android_asset/www/js/utils.js (212)
I/chromium(28058): [INFO:CONSOLE(212)] "Debug: geofencing - Create fence starting 
I/chromium(28058): [INFO:CONSOLE(212)] "Debug: geofencing - Fence locations 
I/chromium(28058): [INFO:CONSOLE(212)] "Debug: geofencing - Create fence starting 
I/chromium(28058): [INFO:CONSOLE(212)] "Debug: geofencing - Fence locations 
I/chromium(28058): [INFO:CONSOLE(212)] "Debug: geofencing - Create fence starting 
I/chromium(28058): [INFO:CONSOLE(212)] "Debug: geofencing - Fence locations 
I/chromium(28058): [INFO:CONSOLE(212)] "Debug: geofencing - Create fence starting 
I/chromium(28058): [INFO:CONSOLE(212)] "Debug: geofencing - Fence locations 
I/chromium(28058): [INFO:CONSOLE(212)] "Debug: geofencing - Create fence starting 
I/chromium(28058): [INFO:CONSOLE(212)] "Debug: geofencing - Fence locations 
I/chromium(28058): [INFO:CONSOLE(212)] "Debug: geofencing - Create fence starting 
I/chromium(28058): [INFO:CONSOLE(212)] "Debug: geofencing - Fence locations 
I/chromium(28058): [INFO:CONSOLE(212)] "Debug: geofencing - Create fence starting 
I/chromium(28058): [INFO:CONSOLE(212)] "Debug: geofencing - Fence locations 
I/chromium(28058): [INFO:CONSOLE(212)] "Debug: geofencing - Create fence starting 
I/chromium(28058): [INFO:CONSOLE(212)] "Debug: geofencing - Fence locations 
I/chromium(28058): [INFO:CONSOLE(212)] "Debug: geofencing - Create fence starting 
I/chromium(28058): [INFO:CONSOLE(212)] "Debug: geofencing - Fence locations 
D/TEST    (28058): cdvfile://localhost/files-external/larky.txt: 11409
D/MediaScannerReceiver(  944): action: android.intent.action.MEDIA_SCANNER_SCAN_FILE path: /storage/emulated/0/Android/data/com.larky.bfcu/files/larky.txt
D/GeofencePlugin(28058): GeofencePlugin execute action: addOrUpdate args: [{"id":"1","transitionType":1,"radius":181,"longitude":-83.74736423076924,"latitude":42.27997646153846}]
D/GeofencePlugin(28058): Connecting location client
W/PluginManager(28058): THREAD WARNING: exec() call to GeofencePlugin.addOrUpdate blocked the main thread for 44ms. Plugin should use CordovaInterface.getThreadPool().
I/chromium(28058): [INFO:CONSOLE(212)] "Debug: geofencing - Geofence 1 added for fence, dist from current location = 115.56544753090603: {"latitude":42.27997646153846,"longitude":-83.74736423076924,"radius":181.37751256193778,"locationIds":[1,2,3,7,10,12,13,18,20,23,28,29,34]}", source: file:///android_asset/www/js/utils.js (212)
D/GeofencePlugin(28058): Google play services connected
D/GeofencePlugin(28058): Adding new geofences
D/dalvikvm(28058): GC_CONCURRENT freed 484K, 4% free 17676K/18248K, paused 1ms+1ms, total 13ms
D/GeofencePlugin(28058): Geofences successfully added
I/chromium(28058): [INFO:CONSOLE(205)] "Geofence successfully added", source: file:///android_asset/www/js/geofencing.js (205)
D/LocationFilter(12202): Forcing stable location. Original location:Location[fused 42.280273,-83.746018 acc=16 et=+23h40m58s147ms {Bundle[{wifiScan=[B@431633b8, noGPSLocation=Location[fused 42.280273,-83.746018 acc=23 et=+23h40m58s147ms {Bundle[mParcelledData.dataSize=292]}], locationType=3}]}] because SMD didn't trigger.
D/GeofencePlugin(28058): GeofencePlugin execute action: addOrUpdate args: [{"id":"2","transitionType":1,"radius":86,"longitude":-83.74742175,"latitude":42.28239275}]
D/GeofencePlugin(28058): ReceiveTransitionsIntentService - onHandleIntent
D/GeofencePlugin(28058): Geofence transition detected
D/GeofencePlugin(28058): Connecting location client
W/PluginManager(28058): THREAD WARNING: exec() call to GeofencePlugin.addOrUpdate blocked the main thread for 19ms. Plugin should use CordovaInterface.getThreadPool().
W/dalvikvm(28058): threadid=37: thread exiting with uncaught exception (group=0x41c3aba8)
I/chromium(28058): [INFO:CONSOLE(212)] "Debug: geofencing - Geofence 2 added for fence, dist from current location = 262.47916985601086: {"latitude":42.28239275,"longitude":-83.74742175,"radius":86.55339540733178,"locationIds":[4,21,25,33]}", source: file:///android_asset/www/js/utils.js (212)
D/GeofencePlugin(28058): Google play services connected
D/GeofencePlugin(28058): Adding new geofences
E/AndroidRuntime(28058): FATAL EXCEPTION: IntentService[ReceiveTransitionsIntentService]
E/AndroidRuntime(28058): Process: com.larky.bfcu, PID: 28058
E/AndroidRuntime(28058): java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed.
E/AndroidRuntime(28058):    at android.database.sqlite.SQLiteConnectionPool.throwIfClosedLocked(SQLiteConnectionPool.java:962)
E/AndroidRuntime(28058):    at android.database.sqlite.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java:599)
E/AndroidRuntime(28058):    at android.database.sqlite.SQLiteConnectionPool.acquireConnection(SQLiteConnectionPool.java:348)
E/AndroidRuntime(28058):    at android.database.sqlite.SQLiteSession.acquireConnection(SQLiteSession.java:894)
E/AndroidRuntime(28058):    at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:834)
E/AndroidRuntime(28058):    at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
E/AndroidRuntime(28058):    at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:144)
E/AndroidRuntime(28058):    at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:133)
E/AndroidRuntime(28058):    at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:197)
E/AndroidRuntime(28058):    at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:237)
E/AndroidRuntime(28058):    at com.cowbell.cordova.geofence.LocalStorage.getItem(LocalStorage.java:57)
E/AndroidRuntime(28058):    at com.cowbell.cordova.geofence.GeoNotificationStore.getGeoNotification(GeoNotificationStore.java:20)
E/AndroidRuntime(28058):    at com.cowbell.cordova.geofence.ReceiveTransitionsIntentService.onHandleIntent(ReceiveTransitionsIntentService.java:69)
E/AndroidRuntime(28058):    at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
E/AndroidRuntime(28058):    at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(28058):    at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime(28058):    at android.os.HandlerThread.run(HandlerThread.java:61)
W/ActivityManager(  750):   Force finishing activity com.larky.bfcu/.Larky
D/GeofencePlugin(28058): GeofencePlugin execute action: addOrUpdate args: [{"id":"3","transitionType":1,"radius":50,"longitude":-83.752731,"latitude":42.281554}]
W/PluginManager(28058): THREAD WARNING: exec() call to GeofencePlugin.addOrUpdate blocked the main thread for 28ms. Plugin should use CordovaInterface.getThreadPool().
I/chromium(28058): [INFO:CONSOLE(212)] "Debug: geofencing - Geofence 3 added for fence, dist from current location = 570.3475050625968: {"latitude":42.281554,"longitude":-83.752731,"radius":50,"locationIds":[5]}", source: file:///android_asset/www/js/utils.js (212)

bromeostasis added a commit to getlarky/cordova-plugin-geofence that referenced this issue Mar 28, 2016
@bromeostasis
Copy link

@Tempus35 any thoughts on the continuing failure? I've still seen my app crash in the foreground like above ☝️ and in the background (though not 100% sure this is the cause for the background failure, but like 75% 😄 ).

@timwright35
Copy link
Author

@bromeostasis I am at a lose really, I know it has to do with the database and storage, ie the database is closed and then it tries to use it only to crash. Maybe there would be a way to check for the closed DB, then reopen if it is. When I get more time, hopefully soon, I can try looking more.

@bromeostasis
Copy link

@Tempus35 thanks for the feedback.

I'm looking at removing the database.close() instances as I've found a couple of sites that indicate they aren't necessary!

http://touchlabblog.tumblr.com/post/24474750219/single-sqlite-connection
http://stackoverflow.com/questions/6608498/best-place-to-close-database-connection

I'll let you know how it goes!

@bromeostasis
Copy link

@Tempus35 hello again! Any chance you've seen/had any experience with this latest failure? #139

Really stumped on this one and it's causing our app to fail after a fewd ays in the background.

Thanks!

@timwright35
Copy link
Author

I have not experienced those, I have not had to test running through many geofences in a period of time though.

@bromeostasis
Copy link

@Tempus35 ok thanks for the response :D

@timwright35
Copy link
Author

@bromeostasis Yup, if I come across something I will post. I have not been using the plugin much of later since the current app I am now working on does not need it.

@mhfen
Copy link

mhfen commented Jul 18, 2016

@bromeostasis @Tempus35 I just opened this Issue #158

It looks like this one is related even though its been closed?

@nabinkumarn
Copy link

nabinkumarn commented Dec 6, 2016

@Tempus35 @bromeostasis I am facing the same issue. Have you found any solution to this problem?

@bromeostasis
Copy link

@nabinkumarn @mhfen it's been a while since I've looked at this, but I believe removing the database.close() instances as referenced here fixed the issue. Give it a shot and let me know.

We're still struggling with #139 to this day, but I don't think we're seeing this issue anymore.

@nabinkumarn
Copy link

@bromeostasis Thanks for the response. I removed all the database.close() and there are no crashes. It seems like problem is fixed for now. About #139 I am not getting any errors right now. I may have to wait some days to get that. Thanks for the help

@bromeostasis
Copy link

@nabinkumarn great, glad it worked out!

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

No branches or pull requests

4 participants