Skip to content

Commit 2fd2d86

Browse files
committed
Fix RejectedExecutionException when using DnsAddressResolverGroup, close AsyncHttpClient#1335
Motivation: AddressResolverGroup adds a listener to the termination future of an EventExecutor when a new AddressResolver is created. The listener calls AddressResolver.close() when the EventExecutor is terminated to give the AddressResolver a chance to release its resources. When using DnsAddressResolverGroup, the AddressResolver.close() will eventually trigger DnsNameResolver.close(), which closes its underlying DatagramChannel. DatagramChannel.close() (or any Channel.close()) will travel through pipeline and trigger EventExecutor.execute() because DnsNameResolver.close() has been invoked from a non-I/O thread. (NB: A terminationFuture is always notified from the GlobalEventExecutor thread.) However, because we are doing this in the listener of the termination future of the terminated EventLoop we are trying to execute a task upon, the attempt to close the channel fails due to RejectedExecutionException. Modifications: - Do not call Channel.close() in DnsNameResolver.close() if the Channel has been closed by EventLoop already Result: No more RejectedExecutionException when shutting down an event loop.
1 parent ae4929a commit 2fd2d86

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

netty-bp/resolver-dns/src/main/java/io/netty/resolver/dns/DnsNameResolver.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,9 @@ public HostsFileEntriesResolver hostsFileEntriesResolver() {
306306
*/
307307
@Override
308308
public void close() {
309-
ch.close();
309+
if (ch.isOpen()) {
310+
ch.close();
311+
}
310312
}
311313

312314
@Override

0 commit comments

Comments
 (0)