You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "pjfanning (via GitHub)" <gi...@apache.org> on 2023/04/14 19:16:42 UTC

[GitHub] [incubator-pekko] pjfanning commented on a diff in pull request #288: =act Refactory AsyncDnsResolver to fix the race condition of `nextId()`

pjfanning commented on code in PR #288:
URL: https://github.com/apache/incubator-pekko/pull/288#discussion_r1167202012


##########
actor/src/main/scala/org/apache/pekko/io/dns/internal/AsyncDnsResolver.scala:
##########
@@ -47,110 +46,149 @@ private[io] final class AsyncDnsResolver(
 
   import AsyncDnsResolver._
 
-  implicit val ec: ExecutionContextExecutor = context.dispatcher
+  initCache(cache)
 
-  // avoid ever looking up localhost by pre-populating cache
-  {
-    val loopback = InetAddress.getLoopbackAddress
-    val (ipv4Address, ipv6Address) = loopback match {
-      case ipv6: Inet6Address => (InetAddress.getByName("127.0.0.1"), ipv6)
-      case ipv4: Inet4Address => (ipv4, InetAddress.getByName("::1"))
-      case unknown            => throw new IllegalArgumentException(s"Loopback address was [$unknown]")
-    }
-    cache.put(
-      "localhost" -> Ip(),
-      DnsProtocol.Resolved("localhost", ARecord("localhost", Ttl.effectivelyForever, loopback) :: Nil),
-      Ttl.effectivelyForever)
-    cache.put(
-      "localhost" -> Ip(ipv6 = false, ipv4 = true),
-      DnsProtocol.Resolved("localhost", ARecord("localhost", Ttl.effectivelyForever, ipv4Address) :: Nil),
-      Ttl.effectivelyForever)
-    cache.put(
-      "localhost" -> Ip(ipv6 = true, ipv4 = false),
-      DnsProtocol.Resolved("localhost", ARecord("localhost", Ttl.effectivelyForever, ipv6Address) :: Nil),
-      Ttl.effectivelyForever)
-
-  }
-
-  // For ask to DNS Client
-  implicit val timeout: Timeout = Timeout(settings.ResolveTimeout)
-
-  val nameServers = settings.NameServers
-
-  val positiveCachePolicy = settings.PositiveCachePolicy
-  val negativeCachePolicy = settings.NegativeCachePolicy
   log.debug(
     "Using name servers [{}] and search domains [{}] with ndots={}",
-    nameServers,
+    settings.NameServers,
     settings.SearchDomains,
     settings.NDots)
 
-  private var requestId: Short = 0
-
-  private def nextId(): Short = {
-    requestId = (requestId + 1).toShort
-    requestId
-  }

Review Comment:
   is there a test case that shows this?
   
   I'm broadly supportive of fixing this - but I am wondering if a singleton actor instance would be a more actor based solution. Actor instances show only be processing 1 message at a time.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org