Create, kill and create again an actor

Who could point me to the documentation on how to create and kill actors?
From what I read from the docs I could kill any actor by sending akka.actor.PoisonPill

Then I’m trying, just for experiment, to create and kill the akka.io.IO(akka.io.Dns) actor.

What I’m doing:

def getActor() = {
  akka.io.IO(akka.io.Dns) !  akka.actor.PoisonPill // create and kill
  akka.io.IO(akka.io.Dns)                          // create new one and return
}

The problem is that after such manipulation I can not lookup any domains via dns resolver. More over akka.http.client does not work as domanis could not be resolved.

Http()(system)
      .singleRequest(
        HttpRequest(
          method = HttpMethods.HEAD,
          uri = uri,
          headers = List(`User-Agent`(USER_AGENT))
        )
      )

Logs:

akka.actor.RepointableActorRef - Message [akka.io.dns.DnsProtocol$Resolve] to Actor[akka://grpcServer/system/IO-DNS#1709053396] was not delivered. [3] dead letters encountered. If this is not an expected behavior then Actor[akka://grpcServer/system/IO-DNS#1709053396] may have terminated unexpectedly. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.

...akka.stream.StreamTcpException: Tcp command [Connect(google.com:80,None,List(),Some(3 seconds),true)] failed because of akka.io.TcpOutgoingConnection$$anon$2: Connect timeout of Some(3 seconds) expired

Why would you stop that IO actor? Do you try to simulate some real scenario by doing that?

Actors are not automatically started again if they are stopped like that. They can be restarted (via supervision) if an error occurs (exc thrown).

Why would you stop that IO actor? Do you try to simulate some real scenario by doing that?

Because of OOM issue. Just want to make a number of lookups, kill it and create again.

Actors are not automatically started again if they are stopped like that.

If I’m not mistaken, I was able to kill Echo actor in such way and then create it again in the same way

var echoActor = system.actorOf(
    akka.routing.FromConfig.props(Echo.props(system)), "echo"
  )

After it was terminated, just create it again

echoActor = system.actorOf(
    akka.routing.FromConfig.props(Echo.props(system)), "echo"
  )

They can be restarted (via supervision) if an error occurs (exc thrown).

Can you provide a minimal supervisor example just for akka.io.IO(akka.io.Dns)
based on https://github.com/akka/akka/blob/v2.6.8/akka-docs/src/test/scala/docs/actor/FaultHandlingDocSpec.scala#L22-L43

It’ll help me a lot.

Is this related to the OOM issue you reported in Resolve 1000+ DNS with async-dns without OOM error

I suggest that you create an issue that include example code of how to reproduce that problem.

IO(Dns) is an Akka extension that is intended to be started once and then it’s running. You can’t stop it from the outside and expect that it will be started again.

1 Like

I suggest that you create an issue that include example code of how to reproduce that problem.

You already provided the link with example.

IO(Dns) is an Akka extension that is intended to be started once and then it’s running.

Even if it crashed there is no way to create new one DNS resolver?
Can you propose any workaround?
Why it can not be created again using smth like that https://github.com/akka/akka/blob/master/akka-actor/src/main/scala/akka/io/Dns.scala#L173-L189

Let’s continue in Resolve 1000+ DNS with async-dns without OOM error then.

As said, extensions are not designed to be stopped. Your attempt of workaround is wrong way of solving this. Better too find the reason for the leak and fix that.