Skip to content

Commit defd0ec

Browse files
authored
Fix a test that was flaky because of BlockHound (#2572)
`kotlinx.coroutines.debug.internal.DebugProbesImpl.updateState` sometimes parks in order to acquire a lock, which leads BlockHound to detect an illegal blocking call. Now, blocking calls inside `DebugProbesImpl` are permitted. Though allowing `updateState` would suffice, the other users of the lock seem safe, too, and are allowed even when it doesn't make much sense to call them from coroutines.
1 parent 1efc9f1 commit defd0ec

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

kotlinx-coroutines-debug/src/CoroutinesBlockHoundIntegration.kt

+12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class CoroutinesBlockHoundIntegration : BlockHoundIntegration {
1818
allowBlockingWhenEnqueuingTasks()
1919
allowServiceLoaderInvocationsOnInit()
2020
allowBlockingCallsInReflectionImpl()
21+
allowBlockingCallsInDebugProbes()
2122
/* The predicates that define that BlockHound should only report blocking calls from threads that are part of
2223
the coroutine thread pool and currently execute a CPU-bound coroutine computation. */
2324
addDynamicThreadPredicate { isSchedulerWorker(it) }
@@ -48,6 +49,17 @@ public class CoroutinesBlockHoundIntegration : BlockHoundIntegration {
4849
}
4950
}
5051

52+
/**
53+
* Allow blocking calls inside [kotlinx.coroutines.debug.internal.DebugProbesImpl].
54+
*/
55+
private fun BlockHound.Builder.allowBlockingCallsInDebugProbes() {
56+
for (method in listOf("install", "uninstall", "hierarchyToString", "dumpCoroutinesInfo", "dumpDebuggerInfo",
57+
"dumpCoroutinesSynchronized", "updateRunningState", "updateState"))
58+
{
59+
allowBlockingCallsInside("kotlinx.coroutines.debug.internal.DebugProbesImpl", method)
60+
}
61+
}
62+
5163
/**
5264
* Allows blocking inside [kotlinx.coroutines.internal.ThreadSafeHeap].
5365
*/

0 commit comments

Comments
 (0)