When BlockHound is installed, do not report GlobalEventExecutor/SingleThreadEventExecutor#takeTask as blocking call. (#10020)

Motivation:

GlobalEventExecutor/SingleThreadEventExecutor#taskQueue is BlockingQueue.

Modifications:

Add allowBlockingCallsInside configuration for GlobalEventExecutor/SingleThreadEventExecutor#takeTask.

Result:

Fixes #9984
When BlockHound is installed, GlobalEventExecutor/SingleThreadEventExecutor#takeTask is not reported as a blocking call.
This commit is contained in:
violetagg 2020-02-11 21:24:41 +02:00 committed by Norman Maurer
parent 160e7f83d8
commit 269896da13
2 changed files with 41 additions and 0 deletions

View File

@ -62,6 +62,13 @@ class Hidden {
"confirmShutdown"
);
builder.allowBlockingCallsInside("io.netty.util.concurrent.GlobalEventExecutor",
"takeTask");
builder.allowBlockingCallsInside(
"io.netty.util.concurrent.SingleThreadEventExecutor",
"takeTask");
builder.allowBlockingCallsInside(
"io.netty.handler.ssl.SslHandler",
"handshake"

View File

@ -35,9 +35,13 @@ import io.netty.handler.ssl.SslProvider;
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
import io.netty.handler.ssl.util.SelfSignedCertificate;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.concurrent.DefaultThreadFactory;
import io.netty.util.concurrent.EventExecutor;
import io.netty.util.concurrent.GlobalEventExecutor;
import io.netty.util.concurrent.ImmediateEventExecutor;
import io.netty.util.concurrent.ImmediateExecutor;
import io.netty.util.concurrent.ScheduledFuture;
import io.netty.util.concurrent.SingleThreadEventExecutor;
import io.netty.util.internal.Hidden.NettyBlockHoundIntegration;
import org.hamcrest.Matchers;
import org.junit.BeforeClass;
@ -48,6 +52,7 @@ import reactor.blockhound.integration.BlockHoundIntegration;
import java.net.InetSocketAddress;
import java.util.ServiceLoader;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
@ -93,6 +98,35 @@ public class NettyBlockHoundIntegrationTest {
}
}
@Test(timeout = 5000L)
public void testGlobalEventExecutorTakeTask() throws InterruptedException {
testEventExecutorTakeTask(GlobalEventExecutor.INSTANCE);
}
@Test(timeout = 5000L)
public void testSingleThreadEventExecutorTakeTask() throws InterruptedException {
SingleThreadEventExecutor executor =
new SingleThreadEventExecutor(new DefaultThreadFactory("test")) {
@Override
protected void run() {
while (!confirmShutdown()) {
Runnable task = takeTask();
if (task != null) {
task.run();
}
}
}
};
testEventExecutorTakeTask(executor);
}
private static void testEventExecutorTakeTask(EventExecutor eventExecutor) throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
ScheduledFuture<?> f = eventExecutor.schedule(latch::countDown, 10, TimeUnit.MILLISECONDS);
f.sync();
latch.await();
}
// Tests copied from io.netty.handler.ssl.SslHandlerTest
@Test
public void testHandshakeWithExecutorThatExecuteDirectory() throws Exception {