Trying to understand what does, and does not work,...
# coroutines
r
Trying to understand what does, and does not work, with coroutines exception stack recovery (no debug agent here, just a vanilla 1.3.50 + 1.3.0 environment). If I do this:
Copy code
fun main() {
  runBlocking {
      throw Exception("e")
  }
}
I see the expected stack with the
main.runBlocking
call in the stack. However, if I change the dispatcher to explicitly specify
Dispatchers.Default
e.g.
runBlocking(Dispatchers.Default)
, then all I see is the
BaseContinuationImpl.resumeWith
in the stack, and the resume point. This is doubly weird, because I thought
Dispatchers.Default
was... well, the default.
o
runBlocking uses the same thread by default
additionally, I think stack recovery might be debug only, I forget.
r
Thanks for the info on
runBlocking
. The docs [1] are not clear about that, but ok. It still doesn't explain the behaviour I'm seeing (basically that means exception stack recovery isn't working even in cases where I thought it was). [1] In https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/run-blocking.html
The default CoroutineDispatcher for this builder is an internal implementation of event loop that processes continuations in this blocked thread until the completion of this coroutine.
and in https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html:
Dispatchers.Default – is used by all standard builder if no dispatcher nor any other ContinuationInterceptor is specified in their context.
Document https://github.com/Kotlin/kotlinx.coroutines/blob/master/docs/debugging.md states:
Overhead of this feature is negligible and it can be safely turned on by default to simplify logging and diagnostic.
Are people generally running with debug mode on in production? Why isn't this enabled by default?
o
I would argue that the runBlocking docs are very clear, it says "in this blocked thread"
r
It says it "processes continuations in this blocked thread", not that it runs the coroutine in this thread.
The guide does have additional details, but at the very least its not consistent, AFAICT.
o
Well, a coroutine is a (series of) continuation, so it does effectively say that.
r
The continuations are the state of the program at the suspension points, not the program itself. If you want to stretch definitions, then I suppose yes, it does say that, but you can't argue it wouldn't be clearer if it just said "runs the coroutine in the blocked thread".