IJPL-165422 Fix Rhizome breaks if exception is thrown under withKernel

`withKernel` method attaches current coroutine to core `kernelCoroutineScope`
If current coroutine is finished with an exception, the cancellation is propagated to the parent job.
This cancels `kernelCoroutineScope` and prevents further usage of the scope. The scope is never recreated, so it becomes impossible to use Rhizome after that.

As a solution, `kernelCoroutineScope` should be a supervisor to avoid it being canceled by children.
We can do that by creating `childScope` under the root scope.

GitOrigin-RevId: fc38d086f4f5b51538ce1173a25d457e1935bb1d
This commit is contained in:
Kate Botsman
2024-11-01 11:52:22 +01:00
committed by intellij-monorepo-bot
parent 1a1f6849ac
commit a5ab71839e

View File

@@ -54,7 +54,8 @@ internal class BackendKernelService(coroutineScope: CoroutineScope) : KernelServ
initWorkspaceClock()
}
handleEntityTypes(transactor(), this)
kernelCoroutineScope.complete(this)
// Create a supervisor child scope to avoid kernel coroutine getting canceled by exceptions coming under `withKernel`
kernelCoroutineScope.complete(this.childScope(name = "KernelCoroutineScope", supervisor = true))
updateDbInTheEventDispatchThread()
}
}