You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
dnsNameResolver isn't closed when AlgoliaHttpClient.close() is invoked. This can cause Caused by: java.net.SocketException: 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.channel.local.LocalEventLoopGroup
import io.netty.channel.socket.oio.OioDatagramChannel
import io.netty.resolver.dns.DnsNameResolverBuilder
object TestAlgolia {
def main(args: Array[String]): Unit = {
println(System.getProperty("sun.net.maxDatagramSockets"))
1.to(300).foreach { i =>
println(s"Create AlgoliaClient ${i}")
try {
val c = new AlgoliaClient("sdfsdfsdfsdf", "sdfsdfsdfsdfs")
c.close()
// Uncomment the below line, and the code will create 300 AlgoliaClient successfully.
// c.httpClient.dnsNameResolver.close()
} catch { case e: Throwable =>
e.printStackTrace()
}
}
}
}
Then, run with sbt -Dsun.net.maxDatagramSockets=3 'runMain scripts.TestAlgolia'. It will fail after creating 3 AlgoliaClients.
The text was updated successfully, but these errors were encountered:
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.
Description
dnsNameResolver
isn't closed whenAlgoliaHttpClient.close()
is invoked. This can causeCaused by: java.net.SocketException: 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 upAlgoliaClient
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:
Then, run with
sbt -Dsun.net.maxDatagramSockets=3 'runMain scripts.TestAlgolia'
. It will fail after creating 3AlgoliaClient
s.The text was updated successfully, but these errors were encountered: