Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close dnsNameResolver in AlgoliaHttpClient.close() #500

tanin47 opened this issue Oct 27, 2018 · 1 comment

Close dnsNameResolver in AlgoliaHttpClient.close() #500

tanin47 opened this issue Oct 27, 2018 · 1 comment


Copy link

@tanin47 tanin47 commented Oct 27, 2018


dnsNameResolver isn't closed when AlgoliaHttpClient.close() is invoked. This can cause Caused by: maximum number of DatagramSockets reached.

This happens when running Playframework locally with its auto-reload magic. It keeps instantiating a new AlgoliaClient when the code is changed. I use Play's shutdown hook to clean up AlgoliaClient properly when the code is reloaded. Unfortunately, dnsNameResolver isn't closed properly.

But, fortunately, dnsNameResolver is a public member, so I still can close it myself. Thanks you for scoping these members to public.

Steps To Reproduce

Here's a simple code to reproduce it:

package scripts

import algolia.{AlgoliaClient, AlgoliaClientConfiguration, AlgoliaHttpClient}
import io.netty.bootstrap.ChannelFactory
import io.netty.resolver.dns.DnsNameResolverBuilder

object TestAlgolia {
  def main(args: Array[String]): Unit = {
    println(System.getProperty("")) { i =>
     println(s"Create AlgoliaClient ${i}")
      try {
        val c = new AlgoliaClient("sdfsdfsdfsdf", "sdfsdfsdfsdfs")
       // Uncomment the below line, and the code will create 300 AlgoliaClient successfully.
       // c.httpClient.dnsNameResolver.close()
      } catch { case e: Throwable =>

Then, run with sbt 'runMain scripts.TestAlgolia'. It will fail after creating 3 AlgoliaClients.

Copy link

@aseure aseure commented Nov 6, 2018

Hello @tanin47 thank you for reporting this issue.

It indeed looks like a bug on our end, and we'll consider closing the DNS resolver on our end to avoid any socket leak. Thank you for reporting this and sorry for the inconvenience it may have caused.

aseure added a commit that referenced this issue Jan 7, 2019
Ant-hem added a commit that referenced this issue Jan 7, 2019
@Ant-hem Ant-hem closed this in #511 Jan 8, 2019
Ant-hem added a commit that referenced this issue Jan 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants