pjfanning opened a new issue, #3705:
URL: https://github.com/apache/pekko/issues/3705
## Summary
`Shard` releases its lease in `postStop` and discards the returned `Future`,
so a failed release is never logged. This is the same class of problem as #3685
(fixed for `ClusterSingletonManager` in #3699), but in cluster sharding.
## Evidence
`cluster-sharding/src/main/scala/org/apache/pekko/cluster/sharding/Shard.scala:1236-1240`:
```scala
override def postStop(): Unit = {
passivateIntervalTask.foreach(_.cancel())
lease.foreach(_.release())
log.debug("{}: Shard [{}] shutting down", typeName, shardId)
}
```
`Lease.release()` returns `Future[Boolean]`. Here both a failed future and a
`false` result (lease not released) are dropped silently.
## Impact
Observability rather than correctness. When the lease backend is unavailable
as a shard stops (hand-off, rebalance, region shutdown), the lease is not
released and nothing says so. The shard's next allocation then waits until the
lease times out, and the logs give no reason for the stall.
## Suggested direction
The shard is stopping, so the result can't be piped back to `self`. Instead,
log directly from the future's callback; the `ActorLogging` adapter is safe to
use from another thread. For example:
```scala
lease.foreach { l =>
import context.dispatcher
val tn = typeName
val id = shardId
l.release().onComplete {
case Success(true) =>
case Success(false) => log.warning("{}: Lease for shard [{}] was not
released", tn, id)
case Failure(t) => log.error(t, "{}: Failed to release lease for
shard [{}]", tn, id)
}
}
```
Also consider guarding against a `release()` that throws synchronously, so
the rest of `postStop` still runs.
## Test
`ShardWithLeaseSpec` / `ClusterShardingLeaseSpec` use `TestLease`. #3699
adds `TestLease.setNextReleaseResult`, which allows a case asserting that a
failed release logs an error when a shard stops.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]