Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix BlockHound false positives related to channels that use locks
Solves #2302
- Loading branch information
1 parent
8df6f5a
commit 4dc588c
Showing
1 changed file
with
27 additions
and
5 deletions.
There are no files selected for viewing
32 changes: 27 additions & 5 deletions
32
kotlinx-coroutines-debug/src/CoroutinesBlockHoundIntegration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,38 @@ | ||
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") | ||
|
||
package kotlinx.coroutines.debug | ||
|
||
import reactor.blockhound.BlockHound | ||
import kotlinx.coroutines.scheduling.* | ||
import reactor.blockhound.* | ||
import reactor.blockhound.integration.* | ||
|
||
@Suppress("UNUSED") | ||
public class CoroutinesBlockHoundIntegration: BlockHoundIntegration { | ||
public class CoroutinesBlockHoundIntegration : BlockHoundIntegration { | ||
|
||
override fun applyTo(builder: BlockHound.Builder) { | ||
builder.addDynamicThreadPredicate { isSchedulerWorker(it) } | ||
builder.nonBlockingThreadPredicate { p -> p.or { mayNotBlock(it) } } | ||
override fun applyTo(builder: BlockHound.Builder): Unit = with(builder) { | ||
allowBlockingCallsInside("kotlinx.coroutines.channels.AbstractSendChannel", "sendSuspend") | ||
// these classes use a lock internally | ||
for (method in listOf( | ||
"pollInternal", "isEmpty", "isFull", "isClosedForReceive", "offerInternal", "offerSelectInternal", | ||
"enqueueSend", "pollInternal", "pollSelectInternal", "enqueueReceiveInternal", "onCancelIdempotent" )) | ||
{ | ||
allowBlockingCallsInside("kotlinx.coroutines.channels.ArrayChannel", method) | ||
} | ||
for (method in listOf("offerInternal", "offerSelectInternal", "updateHead")) { | ||
allowBlockingCallsInside("kotlinx.coroutines.channels.ArrayBroadcastChannel", method) | ||
} | ||
for (method in listOf("checkOffer", "pollInternal", "pollSelectInternal")) { | ||
allowBlockingCallsInside("kotlinx.coroutines.channels.ArrayBroadcastChannel\$Subscriber", method) | ||
} | ||
for (method in listOf("offerInternal", "offerSelectInternal", "pollInternal", "pollSelectInternal", | ||
"onCancelIdempotent")) | ||
{ | ||
allowBlockingCallsInside("kotlinx.coroutines.channels.ConflatedChannel", method) | ||
} | ||
// should be safe; used for sending tasks to a thread pool | ||
allowBlockingCallsInside("java.util.concurrent.ScheduledThreadPoolExecutor", "execute") | ||
addDynamicThreadPredicate { isSchedulerWorker(it) } | ||
nonBlockingThreadPredicate { p -> p.or { mayNotBlock(it) } } | ||
} | ||
|
||
} |