首页 新闻 会员 周边 捐助

DNS not resolved with WebClient in reactor-netty

0
悬赏园豆:100 [待解决问题]

我在使用WebClient请求时,发现dns解析错误。代码如下:

WebClient webClient = WebClient.builder()
                .build();

        Mono<String> mono = webClient.get()
                .uri("https://cloud.tencent.com/")  // 以腾讯云为例
                .retrieve()
                .bodyToMono(String.class);
        System.out.println(mono.block().length());

看起来很简单的代码。却报错了:

Failed to resolve 'cloud.tencent.com' after 7 queries ; nested exception is java.net.UnknownHostException: Failed to resolve 'cloud.tencent.com' after 7 queries

且dns偶尔是可以正常解析的。首先,dns服务器应该是没有问题的,使用java方式是完全没问题的:

InetAddress.getAllByName("cloud.tencent.com")
output: [cloud.tencent.com/61.54.7.136, cloud.tencent.com/61.54.7.188, cloud.tencent.com/61.54.7.162, cloud.tencent.com/61.54.7.144]

环境如下:

  • windows 10
  • java具体版本为1.8.0_321
  • spring-webflux模块版本为5.3.18

具体debug级别日志如下:

2022-08-28 16:20:50:252 [15636] DEBUG 544 1 reactor.util.Loggers - Using Slf4j logging framework
2022-08-28 16:20:50:280 [15636] DEBUG 572 2 io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework
2022-08-28 16:20:50:280 [15636] DEBUG 572 3 io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false
2022-08-28 16:20:50:280 [15636] DEBUG 572 4 io.netty.util.internal.PlatformDependent0 - Java version: 8
2022-08-28 16:20:50:280 [15636] DEBUG 572 5 io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available
2022-08-28 16:20:50:280 [15636] DEBUG 572 6 io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available
2022-08-28 16:20:50:280 [15636] DEBUG 572 7 io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available
2022-08-28 16:20:50:280 [15636] DEBUG 572 8 io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available
2022-08-28 16:20:50:280 [15636] DEBUG 572 9 io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true
2022-08-28 16:20:50:280 [15636] DEBUG 572 10 io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9
2022-08-28 16:20:50:280 [15636] DEBUG 572 11 io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.<init>(long, int): available
2022-08-28 16:20:50:280 [15636] DEBUG 572 12 io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available
2022-08-28 16:20:50:280 [15636] DEBUG 572 13 io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\30107\AppData\Local\Temp (java.io.tmpdir)
2022-08-28 16:20:50:280 [15636] DEBUG 572 14 io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model)
2022-08-28 16:20:50:280 [15636] DEBUG 572 15 io.netty.util.internal.PlatformDependent - Platform: Windows
2022-08-28 16:20:50:280 [15636] DEBUG 572 16 io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 3771203584 bytes
2022-08-28 16:20:50:280 [15636] DEBUG 572 17 io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1
2022-08-28 16:20:50:280 [15636] DEBUG 572 18 io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available
2022-08-28 16:20:50:280 [15636] DEBUG 572 19 io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false
2022-08-28 16:20:50:344 [15636] DEBUG 636 20 io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple
2022-08-28 16:20:50:344 [15636] DEBUG 636 21 io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4
2022-08-28 16:20:50:711 [15636] DEBUG 1003 22 io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false
2022-08-28 16:20:50:711 [15636] DEBUG 1003 23 io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false
2022-08-28 16:20:50:832 [15636] DEBUG 1124 24 io.netty.util.NetUtilInitializations - Loopback interface: lo (Software Loopback Interface 1, 127.0.0.1)
2022-08-28 16:20:50:834 [15636] DEBUG 1126 25 io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200
2022-08-28 16:20:50:847 [15636] DEBUG 1139 26 org.springframework.web.reactive.function.client.ExchangeFunctions - [2c4d1ac] HTTP GET https://cloud.tencent.com/
2022-08-28 16:20:50:857 [15636] DEBUG 1149 27 io.netty.handler.ssl.OpenSsl - netty-tcnative not in the classpath; OpenSslEngine will be unavailable.
2022-08-28 16:20:51:235 [15636] DEBUG 1527 28 io.netty.handler.ssl.JdkSslContext - Default protocols (JDK): [TLSv1.2] 
2022-08-28 16:20:51:235 [15636] DEBUG 1527 29 io.netty.handler.ssl.JdkSslContext - Default cipher suites (JDK): [TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA, TLS_AES_128_GCM_SHA256, TLS_AES_256_GCM_SHA384]
2022-08-28 16:20:51:251 [15636] DEBUG 1543 30 reactor.netty.tcp.TcpResources - [http] resources will use the default LoopResources: DefaultLoopResources {prefix=reactor-http, daemon=true, selectCount=8, workerCount=8}
2022-08-28 16:20:51:251 [15636] DEBUG 1543 31 reactor.netty.tcp.TcpResources - [http] resources will use the default ConnectionProvider: reactor.netty.resources.DefaultPooledConnectionProvider@38be305c
2022-08-28 16:20:51:251 [15636] DEBUG 1543 32 reactor.netty.resources.DefaultLoopIOUring - Default io_uring support : false
2022-08-28 16:20:51:251 [15636] DEBUG 1543 33 reactor.netty.resources.DefaultLoopEpoll - Default Epoll support : false
2022-08-28 16:20:51:251 [15636] DEBUG 1543 34 reactor.netty.resources.DefaultLoopKQueue - Default KQueue support : false
2022-08-28 16:20:51:267 [15636] DEBUG 1559 35 io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 16
2022-08-28 16:20:51:267 [15636] DEBUG 1559 36 io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024
2022-08-28 16:20:51:267 [15636] DEBUG 1559 37 io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096
2022-08-28 16:20:51:267 [15636] DEBUG 1559 38 io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false
2022-08-28 16:20:51:267 [15636] DEBUG 1559 39 io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512
2022-08-28 16:20:51:286 [15636] DEBUG 1578 40 io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available
2022-08-28 16:20:51:402 [15636] DEBUG 1694 41 io.netty.resolver.DefaultHostsFileEntriesResolver - -Dio.netty.hostsFileRefreshInterval: 0
2022-08-28 16:20:51:418 [15636] DEBUG 1710 42 io.netty.resolver.dns.DefaultDnsServerAddressStreamProvider - Default DNS servers: [/192.168.1.1:53, /192.168.0.1:53] (sun.net.dns.ResolverConfiguration)
2022-08-28 16:20:51:418 [15636] DEBUG 1710 43 reactor.netty.resources.PooledConnectionProvider - Creating a new [http] client pool [PoolFactory{evictionInterval=PT0S, leasingStrategy=fifo, maxConnections=500, maxIdleTime=-1, maxLifeTime=-1, metricsEnabled=false, pendingAcquireMaxCount=1000, pendingAcquireTimeout=45000}] for [cloud.tencent.com:443]
2022-08-28 16:20:51:435 [15636] DEBUG 1727 44 io.netty.channel.DefaultChannelId - -Dio.netty.processId: 15636 (auto-detected)
2022-08-28 16:20:51:551 [15636] DEBUG 1843 45 io.netty.channel.DefaultChannelId - -Dio.netty.machineId: bc:17:b8:ff:fe:37:e9:6b (auto-detected)
2022-08-28 16:20:51:551 [15636] DEBUG 1843 46 io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 16
2022-08-28 16:20:51:551 [15636] DEBUG 1843 47 io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 16
2022-08-28 16:20:51:551 [15636] DEBUG 1843 48 io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192
2022-08-28 16:20:51:551 [15636] DEBUG 1843 49 io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 9
2022-08-28 16:20:51:551 [15636] DEBUG 1843 50 io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 4194304
2022-08-28 16:20:51:551 [15636] DEBUG 1843 51 io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256
2022-08-28 16:20:51:551 [15636] DEBUG 1843 52 io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64
2022-08-28 16:20:51:551 [15636] DEBUG 1843 53 io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768
2022-08-28 16:20:51:566 [15636] DEBUG 1858 54 io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192
2022-08-28 16:20:51:566 [15636] DEBUG 1858 55 io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimIntervalMillis: 0
2022-08-28 16:20:51:566 [15636] DEBUG 1858 56 io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: false
2022-08-28 16:20:51:566 [15636] DEBUG 1858 57 io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedByteBuffersPerChunk: 1023
2022-08-28 16:20:51:566 [15636] DEBUG 1858 58 io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled
2022-08-28 16:20:51:566 [15636] DEBUG 1858 59 io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0
2022-08-28 16:20:51:566 [15636] DEBUG 1858 60 io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384
2022-08-28 16:20:51:583 [15636] DEBUG 1875 61 reactor.netty.resources.PooledConnectionProvider - [f4b33a72] Created a new pooled channel, now: 0 active connections, 0 inactive connections and 0 pending acquire requests.
2022-08-28 16:20:51:599 [15636] DEBUG 1891 62 reactor.netty.tcp.SslProvider - [f4b33a72] SSL enabled using engine sun.security.ssl.SSLEngineImpl@16b8bfed and SNI cloud.tencent.com:443
2022-08-28 16:20:51:615 [15636] DEBUG 1907 63 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true
2022-08-28 16:20:51:615 [15636] DEBUG 1907 64 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true
2022-08-28 16:20:51:615 [15636] DEBUG 1907 65 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@51dc06c9
2022-08-28 16:20:51:615 [15636] DEBUG 1907 66 reactor.netty.transport.TransportConfig - [f4b33a72] Initialized pipeline DefaultChannelPipeline{(reactor.left.sslHandler = io.netty.handler.ssl.SslHandler), (reactor.left.sslReader = reactor.netty.tcp.SslProvider$SslReadHandler), (reactor.left.httpCodec = io.netty.handler.codec.http.HttpClientCodec), (reactor.left.httpDecompressor = io.netty.handler.codec.http.HttpContentDecompressor), (reactor.right.reactiveBridge = reactor.netty.channel.ChannelOperationsHandler)}
2022-08-28 16:20:51:635 [15636] DEBUG 1927 67 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@68709c03
2022-08-28 16:20:51:635 [15636] DEBUG 1927 68 io.netty.resolver.dns.DnsQueryContext - [id: 0xc81e0e51] WRITE: UDP, [53122: /192.168.1.1:53], DefaultDnsQuestion(cloud.tencent.com. IN A)
2022-08-28 16:20:51:635 [15636] DEBUG 1927 69 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096
2022-08-28 16:20:51:635 [15636] DEBUG 1927 70 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8
2022-08-28 16:20:51:635 [15636] DEBUG 1927 71 io.netty.util.Recycler - -Dio.netty.recycler.chunkSize: 32
2022-08-28 16:20:51:635 [15636] DEBUG 1927 72 io.netty.util.Recycler - -Dio.netty.recycler.blocking: false
2022-08-28 16:20:51:651 [15636] DEBUG 1943 73 io.netty.resolver.dns.DnsNameResolver - [id: 0xc81e0e51] RECEIVED: UDP [53122: /192.168.1.1:53], DatagramDnsResponse(from: /192.168.1.1:53, to: /0:0:0:0:0:0:0:0:64445, 53122, QUERY(0), NoError(0))
	DefaultDnsQuestion(cloud.tencent.com. IN A)
	DefaultDnsRawRecord(OPT flags:0 udp:4096 0B)
	DefaultDnsRawRecord(cloud.tencent.com. 48 IN A 4B)
2022-08-28 16:20:51:651 [15636] DEBUG 1943 74 io.netty.resolver.dns.DnsQueryContext - [id: 0xc81e0e51] WRITE: UDP, [14556: /192.168.0.1:53], DefaultDnsQuestion(cloud.tencent.com. IN A)
2022-08-28 16:20:51:651 [15636] DEBUG 1943 75 io.netty.resolver.dns.DnsNameResolver - [id: 0xc81e0e51] RECEIVED: UDP [14556: /192.168.0.1:53], DatagramDnsResponse(from: /192.168.0.1:53, to: /0:0:0:0:0:0:0:0:64445, 14556, QUERY(0), NoError(0))
	DefaultDnsQuestion(cloud.tencent.com. IN A)
	DefaultDnsRawRecord(OPT flags:0 udp:4096 0B)
	DefaultDnsRawRecord(cloud.tencent.com. 48 IN A 4B)
2022-08-28 16:20:51:651 [15636] DEBUG 1943 76 io.netty.resolver.dns.DnsQueryContext - [id: 0xc81e0e51] WRITE: UDP, [29164: /192.168.1.1:53], DefaultDnsQuestion(cloud.tencent.com. IN CNAME)
2022-08-28 16:20:51:667 [15636] DEBUG 1959 77 io.netty.resolver.dns.DnsNameResolver - [id: 0xc81e0e51] RECEIVED: UDP [29164: /192.168.1.1:53], DatagramDnsResponse(from: /192.168.1.1:53, to: /0:0:0:0:0:0:0:0:64445, 29164, QUERY(0), NoError(0), RD RA)
	DefaultDnsQuestion(cloud.tencent.com. IN CNAME)
	DefaultDnsRawRecord(cloud.tencent.com. 2808 IN CNAME 25B)
2022-08-28 16:20:51:667 [15636] DEBUG 1959 78 io.netty.resolver.dns.DnsQueryContext - [id: 0xc81e0e51] WRITE: UDP, [6868: /192.168.1.1:53], DefaultDnsQuestion(cloud.tencent-cloud.com. IN CNAME)
2022-08-28 16:20:51:683 [15636] DEBUG 1975 79 io.netty.resolver.dns.DnsNameResolver - [id: 0xc81e0e51] RECEIVED: UDP [6868: /192.168.1.1:53], DatagramDnsResponse(from: /192.168.1.1:53, to: /0:0:0:0:0:0:0:0:64445, 6868, QUERY(0), NoError(0), RD RA)
	DefaultDnsQuestion(cloud.tencent-cloud.com. IN CNAME)
	DefaultDnsRawRecord(cloud.tencent-cloud.com. 97 IN CNAME 33B)
2022-08-28 16:20:51:698 [15636] DEBUG 1990 80 io.netty.resolver.dns.DnsQueryContext - [id: 0xc81e0e51] WRITE: UDP, [54773: /192.168.1.1:53], DefaultDnsQuestion(cloud.tencent.com.dsa.dnsv1.com. IN CNAME)
2022-08-28 16:20:51:736 [15636] DEBUG 2028 81 io.netty.resolver.dns.DnsNameResolver - [id: 0xc81e0e51] RECEIVED: UDP [54773: /192.168.1.1:53], DatagramDnsResponse(from: /192.168.1.1:53, to: /0:0:0:0:0:0:0:0:64445, 54773, QUERY(0), NoError(0), RD RA)
	DefaultDnsQuestion(cloud.tencent.com.dsa.dnsv1.com. IN CNAME)
	DefaultDnsRawRecord(cloud.tencent.com.dsa.dnsv1.com. 433 IN CNAME 32B)
2022-08-28 16:20:51:736 [15636] DEBUG 2028 82 io.netty.resolver.dns.DnsQueryContext - [id: 0xc81e0e51] WRITE: UDP, [47800: /192.168.1.1:53], DefaultDnsQuestion(2794037.sched.d0-dk.tdnsdp1.cn. IN CNAME)
2022-08-28 16:20:51:799 [15636] DEBUG 2091 83 io.netty.resolver.dns.DnsNameResolver - [id: 0xc81e0e51] RECEIVED: UDP [47800: /192.168.1.1:53], DatagramDnsResponse(from: /192.168.1.1:53, to: /0:0:0:0:0:0:0:0:64445, 47800, QUERY(0), NoError(0), RD RA)
	DefaultDnsQuestion(2794037.sched.d0-dk.tdnsdp1.cn. IN CNAME)
	DefaultDnsRawRecord(d0-dk.tdnsdp1.cn. 43 IN SOA 42B)
2022-08-28 16:20:51:799 [15636] DEBUG 2091 84 io.netty.resolver.dns.DnsQueryContext - [id: 0xc81e0e51] WRITE: UDP, [58567: /192.168.0.1:53], DefaultDnsQuestion(2794037.sched.d0-dk.tdnsdp1.cn. IN CNAME)
2022-08-28 16:20:51:814 [15636] DEBUG 2106 85 io.netty.resolver.dns.DnsNameResolver - [id: 0xc81e0e51] RECEIVED: UDP [58567: /192.168.0.1:53], DatagramDnsResponse(from: /192.168.0.1:53, to: /0:0:0:0:0:0:0:0:64445, 58567, QUERY(0), NoError(0), RD RA)
	DefaultDnsQuestion(2794037.sched.d0-dk.tdnsdp1.cn. IN CNAME)
	DefaultDnsRawRecord(d0-dk.tdnsdp1.cn. 43 IN SOA 42B)
Exception in thread "main" org.springframework.web.reactive.function.client.WebClientRequestException: Failed to resolve 'cloud.tencent.com' after 7 queries ; nested exception is java.net.UnknownHostException: Failed to resolve 'cloud.tencent.com' after 7 queries 
	at org.springframework.web.reactive.function.client.ExchangeFunctions$DefaultExchangeFunction.lambda$wrapException$9(ExchangeFunctions.java:141)
	Suppressed: The stacktrace has been enhanced by Reactor, refer to additional information below: 
Error has been observed at the following site(s):
	*__checkpoint ⇢ Request to GET https://cloud.tencent.com/ [DefaultWebClient]
Original Stack Trace:
		at org.springframework.web.reactive.function.client.ExchangeFunctions$DefaultExchangeFunction.lambda$wrapException$9(ExchangeFunctions.java:141)
		at reactor.core.publisher.MonoErrorSupplied.subscribe(MonoErrorSupplied.java:55)
		at reactor.core.publisher.Mono.subscribe(Mono.java:4400)
		at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:103)
		at reactor.core.publisher.FluxPeek$PeekSubscriber.onError(FluxPeek.java:222)
		at reactor.core.publisher.FluxPeek$PeekSubscriber.onError(FluxPeek.java:222)
		at reactor.core.publisher.FluxPeek$PeekSubscriber.onError(FluxPeek.java:222)
		at reactor.core.publisher.MonoNext$NextSubscriber.onError(MonoNext.java:93)
		at reactor.core.publisher.MonoFlatMapMany$FlatMapManyMain.onError(MonoFlatMapMany.java:204)
		at reactor.core.publisher.SerializedSubscriber.onError(SerializedSubscriber.java:124)
		at reactor.core.publisher.FluxRetryWhen$RetryWhenMainSubscriber.whenError(FluxRetryWhen.java:225)
		at reactor.core.publisher.FluxRetryWhen$RetryWhenOtherSubscriber.onError(FluxRetryWhen.java:274)
		at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.drain(FluxConcatMap.java:415)
		at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.onNext(FluxConcatMap.java:251)
		at reactor.core.publisher.EmitterProcessor.drain(EmitterProcessor.java:491)
		at reactor.core.publisher.EmitterProcessor.tryEmitNext(EmitterProcessor.java:299)
		at reactor.core.publisher.SinkManySerialized.tryEmitNext(SinkManySerialized.java:100)
		at reactor.core.publisher.InternalManySink.emitNext(InternalManySink.java:27)
		at reactor.core.publisher.FluxRetryWhen$RetryWhenMainSubscriber.onError(FluxRetryWhen.java:190)
		at reactor.core.publisher.MonoCreate$DefaultMonoSink.error(MonoCreate.java:194)
		at reactor.netty.http.client.HttpClientConnect$MonoHttpConnect$ClientTransportSubscriber.onError(HttpClientConnect.java:304)
		at reactor.core.publisher.MonoCreate$DefaultMonoSink.error(MonoCreate.java:194)
		at reactor.netty.resources.DefaultPooledConnectionProvider$DisposableAcquire.onError(DefaultPooledConnectionProvider.java:155)
		at reactor.core.publisher.FluxContextWrite$ContextWriteSubscriber.onError(FluxContextWrite.java:121)
		at reactor.netty.internal.shaded.reactor.pool.AbstractPool$Borrower.fail(AbstractPool.java:477)
		at reactor.netty.internal.shaded.reactor.pool.SimpleDequePool.lambda$drainLoop$9(SimpleDequePool.java:431)
		at reactor.core.publisher.FluxDoOnEach$DoOnEachSubscriber.onError(FluxDoOnEach.java:186)
		at reactor.core.publisher.MonoCreate$DefaultMonoSink.error(MonoCreate.java:194)
		at reactor.netty.resources.DefaultPooledConnectionProvider$PooledConnectionAllocator$PooledConnectionInitializer.onError(DefaultPooledConnectionProvider.java:538)
		at reactor.core.publisher.MonoFlatMap$FlatMapMain.secondError(MonoFlatMap.java:192)
		at reactor.core.publisher.MonoFlatMap$FlatMapInner.onError(MonoFlatMap.java:259)
		at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:106)
		at reactor.core.publisher.Operators.error(Operators.java:198)
		at reactor.core.publisher.MonoError.subscribe(MonoError.java:53)
		at reactor.core.publisher.Mono.subscribe(Mono.java:4400)
		at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:103)
		at reactor.netty.transport.TransportConnector$MonoChannelPromise.tryFailure(TransportConnector.java:534)
		at reactor.netty.transport.TransportConnector.lambda$doResolveAndConnect$11(TransportConnector.java:341)
		at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:578)
		at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:552)
		at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:491)
		at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:616)
		at io.netty.util.concurrent.DefaultPromise.setFailure0(DefaultPromise.java:609)
		at io.netty.util.concurrent.DefaultPromise.setFailure(DefaultPromise.java:109)
		at io.netty.resolver.InetSocketAddressResolver$2.operationComplete(InetSocketAddressResolver.java:86)
		at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:578)
		at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:571)
		at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:550)
		at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:491)
		at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:616)
		at io.netty.util.concurrent.DefaultPromise.setFailure0(DefaultPromise.java:609)
		at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:117)
		at io.netty.resolver.dns.DnsResolveContext.finishResolve(DnsResolveContext.java:1055)
		at io.netty.resolver.dns.DnsResolveContext.tryToFinishResolve(DnsResolveContext.java:1000)
		at io.netty.resolver.dns.DnsResolveContext.query(DnsResolveContext.java:418)
		at io.netty.resolver.dns.DnsResolveContext.tryToFinishResolve(DnsResolveContext.java:971)
		at io.netty.resolver.dns.DnsResolveContext.access$700(DnsResolveContext.java:66)
		at io.netty.resolver.dns.DnsResolveContext$2.operationComplete(DnsResolveContext.java:471)
		at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:578)
		at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:571)
		at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:550)
		at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:491)
		at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:616)
		at io.netty.util.concurrent.DefaultPromise.setSuccess0(DefaultPromise.java:605)
		at io.netty.util.concurrent.DefaultPromise.trySuccess(DefaultPromise.java:104)
		at io.netty.resolver.dns.DnsQueryContext.trySuccess(DnsQueryContext.java:216)
		at io.netty.resolver.dns.DnsQueryContext.finish(DnsQueryContext.java:208)
		at io.netty.resolver.dns.DnsNameResolver$DnsResponseHandler.channelRead(DnsNameResolver.java:1314)
		at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
		at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
		at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
		at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
		at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
		at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
		at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
		at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
		at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
		at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
		at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
		at io.netty.channel.nio.AbstractNioMessageChannel$NioMessageUnsafe.read(AbstractNioMessageChannel.java:97)
		at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:722)
		at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658)
		at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584)
		at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
		at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
		at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
		at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
		at java.lang.Thread.run(Thread.java:750)
	Suppressed: java.lang.Exception: #block terminated with an error
		at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:99)
		at reactor.core.publisher.Mono.block(Mono.java:1707)
		at com.webflux.beans.Question.main(Question.java:20)
Caused by: java.net.UnknownHostException: Failed to resolve 'cloud.tencent.com' after 7 queries 
	at io.netty.resolver.dns.DnsResolveContext.finishResolve(DnsResolveContext.java:1047)
	at io.netty.resolver.dns.DnsResolveContext.tryToFinishResolve(DnsResolveContext.java:1000)
	at io.netty.resolver.dns.DnsResolveContext.query(DnsResolveContext.java:418)
	at io.netty.resolver.dns.DnsResolveContext.tryToFinishResolve(DnsResolveContext.java:971)
	at io.netty.resolver.dns.DnsResolveContext.access$700(DnsResolveContext.java:66)
	at io.netty.resolver.dns.DnsResolveContext$2.operationComplete(DnsResolveContext.java:471)
	at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:578)
	at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:571)
	at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:550)
	at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:491)
	at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:616)
	at io.netty.util.concurrent.DefaultPromise.setSuccess0(DefaultPromise.java:605)
	at io.netty.util.concurrent.DefaultPromise.trySuccess(DefaultPromise.java:104)
	at io.netty.resolver.dns.DnsQueryContext.trySuccess(DnsQueryContext.java:216)
	at io.netty.resolver.dns.DnsQueryContext.finish(DnsQueryContext.java:208)
	at io.netty.resolver.dns.DnsNameResolver$DnsResponseHandler.channelRead(DnsNameResolver.java:1314)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
	at io.netty.channel.nio.AbstractNioMessageChannel$NioMessageUnsafe.read(AbstractNioMessageChannel.java:97)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:722)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.lang.Thread.run(Thread.java:750)

Process finished with exit code 1
『剑来人间』的主页 『剑来人间』 | 初学一级 | 园豆:102
提问于:2022-08-28 16:25

netty小白,着实不清楚怎么做。

『剑来人间』 2年前
< >
分享
所有回答(1)
0

你的问题看起来可能是由于DNS解析不一致或者 WebClient 没有正确处理 DNS 解析导致的。以下有几种可能的解决方案:

  1. 在其它设备或网络环境中测试这段代码,以确定是否是特定环境下的问题。
  2. 尝试清空你的 DNS 缓存。在命令行运行 ipconfig /flushdns(Windows) 或 sudo killall -HUP mDNSResponder (macOS)。
  3. 使用 Mono.just 替代 .uri 方法:
    Mono<String> mono = webClient.get()
                .uri(URI.create("https://cloud.tencent.com/"))  // 以腾讯云为例
                .retrieve()
                .bodyToMono(String.class);
    
  4. 尝试设置一个自定义的 DNS 解析器,例如使用 Google 的 DNS 服务:
    WebClient webClient = WebClient.builder()
                .clientConnector(new ReactorClientHttpConnector(HttpClient.create().resolver(
                    addressResolverGroupBuilder -> addressResolverGroupBuilder.nameResolverFactory(
                        new DnsNameResolverProvider() {
                            @Override
                            public DnsNameResolver newNameResolver(EventLoop eventLoop, DnsServerAddresses dnsServerAddresses) {
                                return DnsNameResolverBuilder.newBuilder()
                                    .queryTimeoutMillis(5000)
                                    .maxQueriesPerResolve(1)
                                    .nameServerProvider(DnsServerAddresses.sequential(new InetSocketAddress("8.8.8.8", 53)))
                                    .build(eventLoop);
                            }
                        }))))
                .build();
    

以上只是针对你描述的问题提出的一些可能的解决方案,你需要根据你的实际情况尝试。

注意:对 DNS 的改动可能会影响到其它的网络请求,所以只应当在确定问题且无其它解决方案时才考虑使用。

npe0 | 园豆:1502 (小虾三级) | 2023-12-12 17:37
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册