# How to restart the stopped Actor?

**URL:** <https://discuss.akka.io/t/how-to-restart-the-stopped-actor/7363>\
**Category:** Akka Libraries\
**Created:** [October 21, 2020, 5:51pm UTC](https://discuss.akka.io/t/how-to-restart-the-stopped-actor/7363 "2020-10-21T17:51:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![emretanriverdi](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/emretanriverdi/32/2288_2.png) [@emretanriverdi](https://discuss.akka.io/u/emretanriverdi)\
**Post date:** [October 21, 2020, 5:51pm UTC](https://discuss.akka.io/t/how-to-restart-the-stopped-actor/7363/1 "2020-10-21T17:51:07Z")

</div>

Hi everyone,

> <https://github.com/akka/alpakka-kafka/blob/master/core/src/main/scala/akka/kafka/internal/KafkaConsumerActor.scala#L564>

We somehow fall into this NonFatal exception, we can see its log.  
Then the consumer gets stopped and doesn’t restart itself. It stays shut.

Can anyone help why it may occur and maybe we can solve it?  
Or, as a quick workaround, at least how can we auto-restart it?

We have this code in supervisor but it doesn’t help:

case ex: Exception =\>  
Restart

Here is the log message we get:  
[6baf9] Exception when polling from consumer, stopping actor: org.apache.kafka.common.KafkaException: Unexpected error from SyncGroup: The server experienced an unexpected error when processing the request.

---

<div class="post-metadata">

**Author:** ![fxgai](https://avatars.discourse-cdn.com/v4/letter/f/2acd7d/32.png) [@fxgai](https://discuss.akka.io/u/fxgai)\
**Post date:** [October 23, 2020, 2:37am UTC](https://discuss.akka.io/t/how-to-restart-the-stopped-actor/7363/2 "2020-10-23T02:37:56Z")

</div>

I see the actor is stopping itself after logging the exception / error.

The code in the supervisor will work if an exception is thrown, I would guess.

So instead of stopping the actor after logging the exception, how about you instead re-throw the exception? Then the supervision should see it, I imagine.

---

<div class="post-metadata">

**Author:** ![ennru](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/ennru/32/1495_2.png) [@ennru](https://discuss.akka.io/u/ennru)\
**Post date:** [October 23, 2020, 7:43am UTC](https://discuss.akka.io/t/how-to-restart-the-stopped-actor/7363/3 "2020-10-23T07:43:45Z")

</div>

Hi Emre,

I’m don’t know what you are doing, but Alpakka Kafka’s `KafkaConsumerActor` is not meant to be interacted with directly. It is managed from the Akka Streams stages in Alpakka Kafka. Errors in the Kafka Consumer interaction will stop the stream.  
To handle these failures you may wrap the stream in a `RestartSource` as shown in [https://doc.akka.io/docs/alpakka-kafka/current/errorhandling.html](https://doc.akka.io/docs/alpakka-kafka/current/errorhandling.html)

Cheers,  
Enno.

---

<div class="post-metadata">

**Author:** ![emretanriverdi](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/emretanriverdi/32/2288_2.png) [@emretanriverdi](https://discuss.akka.io/u/emretanriverdi)\
**Post date:** [October 25, 2020, 9:04am UTC](https://discuss.akka.io/t/how-to-restart-the-stopped-actor/7363/4 "2020-10-25T09:04:31Z")

</div>

Thank you @ennru, I will try and let you know about it.

---

<div class="post-metadata">

**Author:** ![emretanriverdi](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/emretanriverdi/32/2288_2.png) [@emretanriverdi](https://discuss.akka.io/u/emretanriverdi)\
**Post date:** [October 30, 2020, 6:08pm UTC](https://discuss.akka.io/t/how-to-restart-the-stopped-actor/7363/6 "2020-10-30T18:08:23Z")

</div>

@ennru

it still stops 😕

---

<div class="post-metadata">

**Author:** ![emretanriverdi](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/emretanriverdi/32/2288_2.png) [@emretanriverdi](https://discuss.akka.io/u/emretanriverdi)\
**Post date:** [April 4, 2021, 7:24am UTC](https://discuss.akka.io/t/how-to-restart-the-stopped-actor/7363/7 "2021-04-04T07:24:36Z")

</div>

UPDATE:

This behavior was caused by our VM options. When we reach the memory limit we observed that the Akka actor was stopping itself.

Just a quick heads up for anyone wondering and/or searching for a possible solution.
