@@ -9,7 +9,9 @@ import androidx.annotation.VisibleForTesting
9
9
import kotlinx.coroutines.CoroutineScope
10
10
import kotlinx.coroutines.Dispatchers
11
11
import kotlinx.coroutines.asCoroutineDispatcher
12
+ import kotlinx.coroutines.CoroutineExceptionHandler
12
13
import kotlinx.coroutines.cancelChildren
14
+ import kotlinx.coroutines.plus
13
15
import kotlinx.coroutines.withContext
14
16
import mozilla.appservices.places.PlacesReaderConnection
15
17
import mozilla.appservices.places.PlacesWriterConnection
@@ -36,10 +38,30 @@ abstract class PlacesStorage(
36
38
Executors .newSingleThreadExecutor(
37
39
NamedThreadFactory (" PlacesStorageWriteScope" ),
38
40
).asCoroutineDispatcher(),
39
- )
41
+ ) +
42
+ CoroutineExceptionHandler { _, throwable ->
43
+ // Workaround for https://github.com/Kotlin/kotlinx.coroutines/issues/3328 to prevent
44
+ // adding DiagnosticCoroutineContextException as suppressed exception which is not
45
+ // serializable in 1.6.4. We are otherwise not able to serialize the exception and
46
+ // pass it to our crash reporter. Without a handler on the context, the global handler
47
+ // will otherwise add:
48
+ // runCatching { exception.addSuppressed(DiagnosticCoroutineContextException(context)) }
49
+ val currentThread = Thread .currentThread()
50
+ currentThread.uncaughtExceptionHandler.uncaughtException(currentThread, throwable)
51
+ }
40
52
@VisibleForTesting internal set
41
53
42
- internal var readScope = CoroutineScope (Dispatchers .IO )
54
+ internal var readScope = CoroutineScope (Dispatchers .IO ) +
55
+ CoroutineExceptionHandler { _, throwable ->
56
+ // Workaround for https://github.com/Kotlin/kotlinx.coroutines/issues/3328 to prevent
57
+ // adding DiagnosticCoroutineContextException as suppressed exception which is not
58
+ // serializable in 1.6.4. We are otherwise not able to serialize the exception and
59
+ // pass it to our crash reporter. Without a handler on the context, the global handler
60
+ // will otherwise add:
61
+ // runCatching { exception.addSuppressed(DiagnosticCoroutineContextException(context)) }
62
+ val currentThread = Thread .currentThread()
63
+ currentThread.uncaughtExceptionHandler.uncaughtException(currentThread, throwable)
64
+ }
43
65
@VisibleForTesting internal set
44
66
private val storageDir by lazy { context.filesDir }
45
67
0 commit comments