Skip to content

Commit 915772f

Browse files
committed
1 parent e912335 commit 915772f

File tree

1 file changed

+23
-7
lines changed
  • android-components/components/browser/storage-sync/src/main/java/mozilla/components/browser/storage/sync

1 file changed

+23
-7
lines changed

android-components/components/browser/storage-sync/src/main/java/mozilla/components/browser/storage/sync/PlacesStorage.kt

+23-7
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ package mozilla.components.browser.storage.sync
66

77
import android.content.Context
88
import androidx.annotation.VisibleForTesting
9-
import kotlinx.coroutines.CoroutineScope
10-
import kotlinx.coroutines.Dispatchers
11-
import kotlinx.coroutines.asCoroutineDispatcher
12-
import kotlinx.coroutines.cancelChildren
13-
import kotlinx.coroutines.withContext
9+
import kotlinx.coroutines.*
1410
import mozilla.appservices.places.PlacesReaderConnection
1511
import mozilla.appservices.places.PlacesWriterConnection
1612
import mozilla.appservices.places.uniffi.PlacesApiException
@@ -36,10 +32,30 @@ abstract class PlacesStorage(
3632
Executors.newSingleThreadExecutor(
3733
NamedThreadFactory("PlacesStorageWriteScope"),
3834
).asCoroutineDispatcher(),
39-
)
35+
) +
36+
CoroutineExceptionHandler { _, throwable ->
37+
// Workaround for https://github.com/Kotlin/kotlinx.coroutines/issues/3328 to prevent
38+
// adding DiagnosticCoroutineContextException as suppressed exception which is not
39+
// serializable in 1.6.4. We are otherwise not able to serialize the exception and
40+
// pass it to our crash reporter. Without a handler on the context, the global handler
41+
// will otherwise add:
42+
// runCatching { exception.addSuppressed(DiagnosticCoroutineContextException(context)) }
43+
val currentThread = Thread.currentThread()
44+
currentThread.uncaughtExceptionHandler.uncaughtException(currentThread, throwable)
45+
}
4046
@VisibleForTesting internal set
4147

42-
internal var readScope = CoroutineScope(Dispatchers.IO)
48+
internal var readScope = CoroutineScope(Dispatchers.IO) +
49+
CoroutineExceptionHandler { _, throwable ->
50+
// Workaround for https://github.com/Kotlin/kotlinx.coroutines/issues/3328 to prevent
51+
// adding DiagnosticCoroutineContextException as suppressed exception which is not
52+
// serializable in 1.6.4. We are otherwise not able to serialize the exception and
53+
// pass it to our crash reporter. Without a handler on the context, the global handler
54+
// will otherwise add:
55+
// runCatching { exception.addSuppressed(DiagnosticCoroutineContextException(context)) }
56+
val currentThread = Thread.currentThread()
57+
currentThread.uncaughtExceptionHandler.uncaughtException(currentThread, throwable)
58+
}
4359
@VisibleForTesting internal set
4460
private val storageDir by lazy { context.filesDir }
4561

0 commit comments

Comments
 (0)