Skip to content

Commit bdd3d7d

Browse files
authored
fix: shutdown DNS event loop when closing HTTP client (#651)
1 parent c36dbf3 commit bdd3d7d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/main/scala/algolia/AlgoliaHttpClient.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
package algolia
2727

2828
import java.util.concurrent.ExecutionException
29-
3029
import algolia.http._
30+
import io.netty.channel.EventLoop
3131
import io.netty.channel.nio.NioEventLoopGroup
3232
import io.netty.channel.socket.nio.NioDatagramChannel
3333
import io.netty.resolver.dns.{DnsNameResolver, DnsNameResolverBuilder}
@@ -52,8 +52,9 @@ case class AlgoliaHttpClient(
5252
.setUseProxyProperties(configuration.useSystemProxy)
5353
.build
5454

55+
val dnsEventLoop: EventLoop = new NioEventLoopGroup(1).next()
5556
val dnsNameResolver: DnsNameResolver =
56-
new DnsNameResolverBuilder(new NioEventLoopGroup(1).next()) //We only need 1 thread for DNS resolution
57+
new DnsNameResolverBuilder(dnsEventLoop) //We only need 1 thread for DNS resolution
5758
.channelType(classOf[NioDatagramChannel])
5859
.queryTimeoutMillis(configuration.dnsTimeoutMs.toLong)
5960
.maxQueriesPerResolve(2)
@@ -67,6 +68,7 @@ case class AlgoliaHttpClient(
6768

6869
def close(): Unit = {
6970
dnsNameResolver.close()
71+
dnsEventLoop.shutdownGracefully()
7072
_httpClient.close()
7173
}
7274

0 commit comments

Comments
 (0)