-
Notifications
You must be signed in to change notification settings - Fork 623
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
Thread safety broken in 1.2.0 (Kotlin 1.5) #1455
Comments
sorry, formatted repro code:
|
Try to compare doubles with delta |
That's not the issue. The errors are mostly json that is invalid and fails to be parsed.
|
@bsimon36 makes sense, sorry for missing that point |
I should note that we caught this in production. The problem only occurs with enough multi-threading so it is likely that people will test the new version, think it's working fine, but then have it break (in possibly hard-to-detect ways) when deployed to an actual server serving many requests simultaneously. |
I have seen this too on my local machine when testing with latest Ktor server api and latest Kotlin. Every few refreshes I receive a garbled JSON from one of the calls. Downgrading to earlier version of this framework fixes the issue and makes the output consistent again.. |
We also faced that issue with import kotlinx.coroutines.*
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
@Serializable
data class Foo(val bar: Bar, val baz: String? = null)
@Serializable
data class Bar(val string: String, val integer: Int, val double: Double, val boolean: Boolean)
fun main() = runBlocking {
val foo1 = Foo(Bar("string1", 1, 1.0, true), "baz1")
val foo2 = Foo(Bar("string2", 2, 2.0, false))
repeat(1_000) {
CoroutineScope(Dispatchers.Default).launch {
Json.decodeFromString<Foo>(Json.encodeToString(foo1))
}
CoroutineScope(Dispatchers.Default).launch {
Json.decodeFromString<Foo>(Json.encodeToString(foo2))
}
delay(1)
}
} As you realize, encoded string values are garbled with each other.
When we revert back to |
Oops. I opened an issue in https://youtrack.jetbrains.com/issue/KT-46623 about this problem. |
@qwwdfsad and @sandwwraith, Please consider un-releasing 1.2.0. This is a pretty serious issue that may sneak to production undetected, and break a lot of stuff. In my case, it cause a lot of errors (local and with server) as well as exposed a battery draining bug (#1474) -- Seems very bad to let people upgrade to 1.2.0 knowing that these are likely to happen. Pull it until there is a patch with a fix. |
Can confirm that I've seen this issue and it appears to be quite serious. |
We'll release 1.2.1 around tomorrow with all the fixes. Unfortunately, we cannot revoke 1.2.0 from MC, so the best we can do here is a clear warning during all the announcements |
@qwwdfsad perhaps, the "What's new in Kotlin 1.5" https://kotlinlang.org/docs/whatsnew15.html#serialization-1-2-0 could be updated to mention 1.2.1 instead of 1.2.0 |
Describe the bug
Thread safety seems to be broken in the newest version, causing the outputs of Json.encodeToString to get garbled with each other.
To Reproduce
for (i in 1..1000) {
thread {
val obj = (1..10000).map { Math.random() }
if (obj != Json.decodeFromString<List>(Json.encodeToString(obj))) {
println("Oh no!")
}
}
}
Expected behavior
Should run fine, instead prints out lots of errors from invalid json and also some "Oh no!"s
Environment
The text was updated successfully, but these errors were encountered: