<https://pl.kotl.in/kbrTePWXD> the following runs...
# coroutines
v
https://pl.kotl.in/kbrTePWXD the following runs into a deadlock(?) in kotlin 1.3.72; all the default dispatcher worker threads are in a MONITOR state 🤔 can someone point me in the direction to figuring this out?
return synchronized(lock) {
val _v2 = _value
if (_v2 !== UNINITIALIZED_VALUE) {
@Suppress("UNCHECKED_CAST") (_v2 as T)
} else {
val typedValue = initializer!!() <-- gets till this invocation and then blocked
_value = typedValue
initializer = null
typedValue
}
}
s
Looks like the code of a
lazy
delegate….
v
yes, i was setting a debug point to see how far it got
s
What happens if you decrease the
concurrency
value to 64 (or a bit less)?
v
reducing concurrency works
whatever kotlin version play.kotlinlang is on, also works regardless of concurrency
so I'm assuming there's a workaround for 1.3.72 🤞
s
I have such a nagging feeling that all (at least 64 of them) the asyncs (the 128 of them) are executing and suspending. Then a blocking
lazy{ .. }
is executed for the
lz
variable that can’t finish, since there are no threads left to run that
test
function…
If the many
async
were to be scheduled in a bit more sequential fashion, not all 64 IO threads would be unavailable? What happens if you don’t make
lz
lazy, but just
val lz = Obj()
?
v
that works ¯\_(ツ)_/¯
but Obj init is a bit costly 😞
w
What if you used a lazy
Deferred
instead?
v
then I'll have to change a bunch of legacy code to be suspend so I can do a .await
👍 1
which I can't
w
From non-suspending context you could have a delegated
by lazy { runBlocking { …
. Just throwing ideas
s
Couldn’t you move
val lz = Obj()
as the first statement in the GlobalScope.launch?
Copy code
GlobalScope.launch {
    val lz = with(<http://Dispatchers.IO|Dispatchers.IO>) { Obj() } // use IO, since creation of Obj() is blocking
    val concurrency = 128
    ...
}
v
I figure this is happening because Dispatchers.IO is "full" (64 already running) and another withContext/runBlocking(Dispatchers.IO) cannot start up but why does the same code work on 1.4