From f9607c628a0f0f56b9a8f0d6ab8336ace7d2b1cd Mon Sep 17 00:00:00 2001 From: dkhalanskyjb <52952525+dkhalanskyjb@users.noreply.github.com> Date: Tue, 16 Nov 2021 16:23:20 +0300 Subject: [PATCH] Fix false positive in WorkQueue.addLast (#2968) Fixes #2937 --- .../src/CoroutinesBlockHoundIntegration.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kotlinx-coroutines-debug/src/CoroutinesBlockHoundIntegration.kt b/kotlinx-coroutines-debug/src/CoroutinesBlockHoundIntegration.kt index e13bc06aa0..e7fe1e6c34 100644 --- a/kotlinx-coroutines-debug/src/CoroutinesBlockHoundIntegration.kt +++ b/kotlinx-coroutines-debug/src/CoroutinesBlockHoundIntegration.kt @@ -19,6 +19,7 @@ public class CoroutinesBlockHoundIntegration : BlockHoundIntegration { allowServiceLoaderInvocationsOnInit() allowBlockingCallsInReflectionImpl() allowBlockingCallsInDebugProbes() + allowBlockingCallsInWorkQueue() // Stacktrace recovery cache is guarded by lock allowBlockingCallsInside("kotlinx.coroutines.internal.ExceptionsConstructorKt", "tryCopyException") /* The predicates that define that BlockHound should only report blocking calls from threads that are part of @@ -62,6 +63,14 @@ public class CoroutinesBlockHoundIntegration : BlockHoundIntegration { } } + /** + * Allow blocking calls inside [kotlinx.coroutines.scheduling.WorkQueue] + */ + private fun BlockHound.Builder.allowBlockingCallsInWorkQueue() { + /** uses [Thread.yield] in a benign way. */ + allowBlockingCallsInside("kotlinx.coroutines.scheduling.WorkQueue", "addLast") + } + /** * Allows blocking inside [kotlinx.coroutines.internal.ThreadSafeHeap]. */