-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Coroutines Exceptions Violate Serializable Interface #3328
Comments
Could not reproduce. The test: import kotlinx.coroutines.*
import org.junit.jupiter.api.*
import java.io.*
import java.util.concurrent.*
class Reproducer3328 {
@Test
fun testSerialization() {
val cdl = CountDownLatch(1)
val bos = ByteArrayOutputStream()
val lifecycleScope = CoroutineScope(CoroutineExceptionHandler { coroutineContext, throwable ->
ObjectOutputStream(bos).use {
it.writeObject(throwable)
cdl.countDown()
}
})
lifecycleScope.launch {
throw RuntimeException("I will blow up when you try to serialize later")
}
cdl.await()
println(bos)
}
} The output for me is the expected byte soup with some plausibly-looking strings embedded:
The version is 1.6.2. |
It is trickier to reproduce. You need a wrapped exception. The root cause of the problem is that |
The same issue is also present in |
Thanks for looking into this issue so quickly! I tested the 1.6.4 release, and I don't think the issue is completely resolved. I managed to generate this exception trying to serialize an exception. The project is open source, so I created a branch that will reproduce the issue. The two links show where the exception is generated and where it tries to serialize it. https://github.com/zcash/secant-android-wallet/tree/coroutines-serialization-bug
|
Could you please point out the test which I should run in order to reproduce the crash? Or should I launch the app and click somewhere? |
You'd have to run the app from that branch. If you open the debug build, there's a overflow menu during onboarding to prefill in a seed phrase. Then once you're at the app's Home Screen, there's another debug menu with an option to trigger an uncaught exception. Do you want to give that a try? I can trigger our CI server to create the APK, but if you want to check out the project and build it that works too. |
Thanks! The reason was the diagnostic exception that was itself serializable, but transitively got non-serializable |
…n#3337) * Ensure that all coroutines throwables in core are serializable Fixes Kotlin#3328
When is this going to be released please? Is there a temp work around? |
OVERVIEW
The Java
Throwable
interface implementsSerializable
. However, certain coroutines classes such askotlinx.coroutines.CoroutinesInternalError
do not correctly implementSerializable
and will cause an exception to be thrown if serialization is attempted.STEPS TO REPRODUCE
RESULTS
Expected
Serialization succeeds
Actual
Serialization fails because
kotlinx.coroutines.CoroutinesInternalError
does not correctly implement Serializable and will cause an exception to be thrown if serialization is attempted. (See #76).The use case where I found this issue is implementing an application-wide UncaughtExceptionHandler under the JVM. In my particular case, I was using the Serializable interface on Throwable to send the exception across process boundaries for logging.
Example stack trace:
NOTES
Reproduced with 1.6.2
The text was updated successfully, but these errors were encountered: