From b1ce20c08084703100c71fd51bb6b3e82033807a Mon Sep 17 00:00:00 2001 From: Violeta Georgieva Date: Thu, 11 Feb 2021 12:03:20 +0200 Subject: [PATCH] Allow blocking calls when parsing etcResolver/hosts files (#11009) Motivation: When etcResolver/hosts files are parsed, FileInputStream.read(...) is internally called by - UnixResolverDnsServerAddressStreamProvider#parseEtcResolverSearchDomains - UnixResolverDnsServerAddressStreamProvider#parseEtcResolverOptions - HostsFileParser#parse This will cause the error below when BlockHound is enabled reactor.blockhound.BlockingOperationError: Blocking call! java.io.FileInputStream#readBytes at java.io.FileInputStream.readBytes(FileInputStream.java) at java.io.FileInputStream.read(FileInputStream.java:255) Modifications: - Add whitelist entries to BlockHound configuration - Fix typos in UnixResolverDnsServerAddressStreamProvider - Add tests Result: Fixes #11004 --- .../java/io/netty/util/internal/Hidden.java | 12 +++++++ ...esolverDnsServerAddressStreamProvider.java | 6 ++-- .../NettyBlockHoundIntegrationTest.java | 33 ++++++++++++++++--- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/io/netty/util/internal/Hidden.java b/common/src/main/java/io/netty/util/internal/Hidden.java index f0e878681c..043c561609 100644 --- a/common/src/main/java/io/netty/util/internal/Hidden.java +++ b/common/src/main/java/io/netty/util/internal/Hidden.java @@ -113,6 +113,18 @@ class Hidden { "io.netty.resolver.dns.UnixResolverDnsServerAddressStreamProvider", "parse"); + builder.allowBlockingCallsInside( + "io.netty.resolver.dns.UnixResolverDnsServerAddressStreamProvider", + "parseEtcResolverSearchDomains"); + + builder.allowBlockingCallsInside( + "io.netty.resolver.dns.UnixResolverDnsServerAddressStreamProvider", + "parseEtcResolverOptions"); + + builder.allowBlockingCallsInside( + "io.netty.resolver.HostsFileParser", + "parse"); + builder.nonBlockingThreadPredicate(p -> thread -> p.test(thread) || thread instanceof FastThreadLocalThread); } diff --git a/resolver-dns/src/main/java/io/netty/resolver/dns/UnixResolverDnsServerAddressStreamProvider.java b/resolver-dns/src/main/java/io/netty/resolver/dns/UnixResolverDnsServerAddressStreamProvider.java index 02c4440ece..cc0ba6ad63 100644 --- a/resolver-dns/src/main/java/io/netty/resolver/dns/UnixResolverDnsServerAddressStreamProvider.java +++ b/resolver-dns/src/main/java/io/netty/resolver/dns/UnixResolverDnsServerAddressStreamProvider.java @@ -87,7 +87,7 @@ public final class UnixResolverDnsServerAddressStreamProvider implements DnsServ * the default DNS server to use, and also overrides for individual domains. Also parse list of files of the format * - * /etc/resolver which may contain multiple files to override the name servers used for multimple domains. + * /etc/resolver which may contain multiple files to override the name servers used for multiple domains. * @param etcResolvConf /etc/resolv.conf. * @param etcResolverFiles List of files of the format defined in * - * /etc/resolver which may contain multiple files to override the name servers used for multimple domains. + * /etc/resolver which may contain multiple files to override the name servers used for multiple domains. * @param etcResolvConf /etc/resolv.conf. * @param etcResolverDir Directory containing files of the format defined in * result = new ArrayList<>(); + List result = new ArrayList<>(); List error = new ArrayList<>(); executor.execute(() -> { try { - result.add(DnsServerAddressStreamProviders.unixDefault()); + result.add(callable.call()); } catch (Throwable t) { error.add(t); }