I have been dealing with an intermittent coroutine related issue for some time now in my Spring Boot server project. I have a custom coroutine scope:
Copy code
class AppIOCoroutineScope : CoroutineScope by CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO>)
When I receive a webhook from an external service, I create a background job like:
Copy code
appIOCoroutineScope.launch {
// do the work
}
Eventually, the coroutine never launches. The first line in the launch block is a log statement which I do not see in my logs when I detect that this job isn't running. A server restart always fixes the issue.
I've taken various thread dumps at this point and nothing has stuck out to me like the usual deadlocks. Are there any coroutine debug tools that I can use to better understand what's going on here?
m
mkrussel
06/13/2022, 9:32 PM
You probably want to add a
SupervisorJob
to the scope.
➕ 1
d
Daniel Skogquist Åborg
06/14/2022, 5:43 PM
Also have a look at CoroutineExceptionHandler when you run with a SupervisorJob to allow you to catch unhandled exceptions if your coroutine crashes.