Skip to content

Commit

Permalink
Fix BlockHound false positives related to channels that use locks
Browse files Browse the repository at this point in the history
Solves #2302
  • Loading branch information
dkhalanskyjb committed Oct 22, 2020
1 parent 20ca97a commit d69bf24
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions kotlinx-coroutines-debug/src/CoroutinesBlockHoundIntegration.kt
@@ -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) } }
}

}

0 comments on commit d69bf24

Please sign in to comment.