Skip to content

Commit 6c9e253

Browse files
committed
when retrying to get SQLite db, throw first exception
* When we retry getting the SQLite database up to 5 times, let's throw the first `SQLiteCantOpenDatabaseException` or `SQLiteDatabaseLockedException` encountered instead of the last one. * This may help give insight into a root cause for crashes seen about: - Cannot open database - OneSignal.db doesn't exist - unknown error (code 14): Could not open database
1 parent 6ad8bfa commit 6c9e253

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignalDbHelper.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,19 @@ private SQLiteDatabase getSQLiteDatabase() {
168168
*/
169169
private SQLiteDatabase getSQLiteDatabaseWithRetries() {
170170
synchronized (LOCK) {
171+
// Throw the first exception as this may give more insight into the root cause of issue:
172+
// https://github.com/OneSignal/OneSignal-Android-SDK/issues/1432
173+
SQLiteException firstSQLiteException = null;
171174
int count = 0;
172175
while (true) {
173176
try {
174177
return getSQLiteDatabase();
175178
} catch (SQLiteCantOpenDatabaseException | SQLiteDatabaseLockedException e) {
179+
if (firstSQLiteException == null) {
180+
firstSQLiteException = e;
181+
}
176182
if (++count >= DB_OPEN_RETRY_MAX)
177-
throw e;
183+
throw firstSQLiteException;
178184
SystemClock.sleep(count * DB_OPEN_RETRY_BACKOFF);
179185
}
180186
}

0 commit comments

Comments
 (0)