I'm getting OutOfMemory errors (JVM) which `superv...
# coroutines
d
I'm getting OutOfMemory errors (JVM) which
supervisorScope
is catching, reporting, and ignoring. I don't see any means to tell
supervisorScope
to not catch fatal errors. Am I missing something? Is there a better pattern? (I guess I could just use `try..catch`to keep non-fatal errors from cancelling the parent?) Fatal errors = OOM, VirtualMachineError, ThreadDeath, LinkageError, InterruptedException, CancellationException.
Reading more about
supervisorScope
and I think it's too robust for our use 😞 . From what I can tell, it's design is to catch all errors even fatal ones allowing the throwing coroutine to die but none of its siblings nor future ones. I may add a side effect to the CoroutineExceptionHandler to set a semaphore if fatal error and use that to abandon the top level iteration unless anyone has a better idea.
y
I mean, theoretically an OOM that happened deep in a coroutine might not affect its siblings after that coroutine is dead, so maybe you actually want this behaviour? Also, I think you could create a version of
SupervisorJob
using Arrow's
nonFatalOrThrow
j
Believe this might be what your looking for, you can create a exception handler and add it to a scope you create or pass it in your launch call. it extends
CoroutineContext.Element
so can be added to other context elements and will allow for custom exception handling https://kotlinlang.org/docs/exception-handling.html