View Javadoc
1   /*
2    * Copyright 2019 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  
17  package io.netty5.util.internal;
18  
19  import io.netty5.util.concurrent.FastThreadLocalThread;
20  import reactor.blockhound.BlockHound;
21  import reactor.blockhound.integration.BlockHoundIntegration;
22  
23  
24  /**
25   * Contains classes that must have public visibility but are not public API.
26   */
27  class Hidden {
28  
29      /**
30       * This class integrates Netty with BlockHound.
31       * <p>
32       * It is public but only because of the ServiceLoader's limitations
33       * and SHOULD NOT be considered a public API.
34       */
35      @UnstableApi
36      public static final class NettyBlockHoundIntegration implements BlockHoundIntegration {
37  
38          @Override
39          public void applyTo(BlockHound.Builder builder) {
40              builder.allowBlockingCallsInside(
41                      "io.netty5.channel.nio.NioEventLoop",
42                      "handleLoopException"
43              );
44  
45              builder.allowBlockingCallsInside(
46                      "io.netty5.channel.kqueue.KQueueEventLoop",
47                      "handleLoopException"
48              );
49  
50              builder.allowBlockingCallsInside(
51                      "io.netty5.channel.epoll.EpollEventLoop",
52                      "handleLoopException"
53              );
54  
55              builder.allowBlockingCallsInside(
56                      "io.netty5.util.HashedWheelTimer",
57                      "start"
58              );
59  
60              builder.allowBlockingCallsInside(
61                      "io.netty5.util.HashedWheelTimer",
62                      "stop"
63              );
64  
65              builder.allowBlockingCallsInside(
66                      "io.netty5.util.HashedWheelTimer$Worker",
67                      "waitForNextTick"
68              );
69  
70              builder.allowBlockingCallsInside(
71                      "io.netty5.util.concurrent.SingleThreadEventExecutor",
72                      "confirmShutdown"
73              );
74              builder.allowBlockingCallsInside("io.netty5.util.concurrent.GlobalEventExecutor",
75                      "addTask");
76  
77              builder.allowBlockingCallsInside("io.netty5.util.concurrent.GlobalEventExecutor",
78                      "takeTask");
79  
80              builder.allowBlockingCallsInside(
81                      "io.netty5.util.concurrent.SingleThreadEventExecutor",
82                      "addTask");
83  
84              builder.allowBlockingCallsInside(
85                      "io.netty5.util.concurrent.SingleThreadEventExecutor",
86                      "takeTask");
87  
88              builder.allowBlockingCallsInside(
89                      "io.netty5.handler.ssl.SslHandler",
90                      "handshake"
91              );
92  
93              builder.allowBlockingCallsInside(
94                      "io.netty5.handler.ssl.SslHandler",
95                      "runAllDelegatedTasks"
96              );
97              builder.allowBlockingCallsInside(
98                      "io.netty5.handler.ssl.SslHandler",
99                      "runDelegatedTasks"
100             );
101 
102             builder.allowBlockingCallsInside(
103                     "io.netty5.handler.ssl.ReferenceCountedOpenSslClientContext$ExtendedTrustManagerVerifyCallback",
104                     "verify");
105 
106             builder.allowBlockingCallsInside(
107                     "io.netty.handler.ssl.JdkSslContext$Defaults",
108                     "init");
109 
110             // Let's whitelist SSLEngineImpl.unwrap(...) for now as it may fail otherwise for TLS 1.3.
111             // See https://mail.openjdk.java.net/pipermail/security-dev/2020-August/022271.html
112             builder.allowBlockingCallsInside(
113                     "sun.security.ssl.SSLEngineImpl",
114                     "unwrap");
115 
116             builder.allowBlockingCallsInside(
117                     "sun.security.ssl.SSLEngineImpl",
118                     "wrap");
119 
120             builder.allowBlockingCallsInside(
121                     "io.netty5.resolver.dns.UnixResolverDnsServerAddressStreamProvider",
122                     "parse");
123 
124             builder.allowBlockingCallsInside(
125                     "io.netty5.resolver.dns.UnixResolverDnsServerAddressStreamProvider",
126                     "parseEtcResolverSearchDomains");
127 
128             builder.allowBlockingCallsInside(
129                     "io.netty5.resolver.dns.UnixResolverDnsServerAddressStreamProvider",
130                     "parseEtcResolverOptions");
131 
132             builder.allowBlockingCallsInside(
133                     "io.netty5.resolver.HostsFileEntriesProvider$ParserImpl",
134                     "parse");
135 
136             builder.allowBlockingCallsInside(
137                     "io.netty5.util.NetUtil$SoMaxConnAction",
138                     "run");
139 
140             builder.nonBlockingThreadPredicate(p -> thread ->
141                     p.test(thread) || thread instanceof FastThreadLocalThread);
142         }
143     }
144 }