diff --git a/cluster-sharding/src/main/scala/org/apache/pekko/cluster/sharding/ShardRegion.scala b/cluster-sharding/src/main/scala/org/apache/pekko/cluster/sharding/ShardRegion.scala index 18b002c4767..6aa943e0b8b 100644 --- a/cluster-sharding/src/main/scala/org/apache/pekko/cluster/sharding/ShardRegion.scala +++ b/cluster-sharding/src/main/scala/org/apache/pekko/cluster/sharding/ShardRegion.scala @@ -1003,8 +1003,9 @@ private[pekko] class ShardRegion( shardsByRef = shardsByRef - ref shards = shards - shardId startingShards -= shardId - if (settings.passivationStrategy != ClusterShardingSettings.NoPassivationStrategy) { - shards.values.foreach(_ ! ShardsUpdated(shards.size)) + if (settings.passivationStrategy != ClusterShardingSettings.NoPassivationStrategy && !gracefulShutdownInProgress) { + val update = ShardsUpdated(shards.size) + shards.values.foreach(_ ! update) } if (handingOff.contains(ref)) { handingOff = handingOff - ref @@ -1348,7 +1349,8 @@ private[pekko] class ShardRegion( shards = shards.updated(id, shard) startingShards += id if (settings.passivationStrategy != ClusterShardingSettings.NoPassivationStrategy) { - shards.values.foreach(_ ! ShardsUpdated(shards.size)) + val update = ShardsUpdated(shards.size) + shards.values.foreach(_ ! update) } None case Some(_) =>