@@ -6,11 +6,7 @@ package mozilla.components.browser.storage.sync
6
6
7
7
import android.content.Context
8
8
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.*
14
10
import mozilla.appservices.places.PlacesReaderConnection
15
11
import mozilla.appservices.places.PlacesWriterConnection
16
12
import mozilla.appservices.places.uniffi.PlacesApiException
@@ -36,10 +32,30 @@ abstract class PlacesStorage(
36
32
Executors .newSingleThreadExecutor(
37
33
NamedThreadFactory (" PlacesStorageWriteScope" ),
38
34
).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
+ }
40
46
@VisibleForTesting internal set
41
47
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
+ }
43
59
@VisibleForTesting internal set
44
60
private val storageDir by lazy { context.filesDir }
45
61
0 commit comments