pekko icon indicating copy to clipboard operation
pekko copied to clipboard

handle the case where `DeviceTerminated.groupId` may not match the `DeviceGroup.groupId`

Open Ghurtchu opened this issue 1 year ago • 2 comments

I was following the online tutorial on the official Pekko website: https://pekko.apache.org/docs/pekko/current/typed/guide/tutorial_4.html#:~:text=Keeping%20track%20of,%C2%B6

and I found that DeviceTerminated.groupId may not match with DeviceGroup.groupId but we don't handle such a case right now. I suggest that we keep consistency and fix it. Since such an approach is already used with RequestTrackDevice message when grId != groupId we could just add a new case in the end to log the warning about the possible scenario here: https://github.com/apache/pekko/blob/58fa510455190bd62d04f92a83c9506a7588d29c/docs/src/test/scala/typed/tutorial_4/DeviceGroup.scala#L85

case DeviceTerminated(_, grId, deviceId) =>
    context.log.warnN("Ignoring DeviceTerminated for groupId:{} and deviceId:{}. This actor is responsible for {}", grId, deviceId, groupId)
    this

Ghurtchu avatar May 04 '24 16:05 Ghurtchu

Thanks for your report, could you submit a pr

laglangyue avatar May 07 '24 03:05 laglangyue

DeviceTerminated only sends if the child actor is terminated, it will always match groups, i don't think there have any issue on there. Could you make a minimal reproduction?

      case trackMsg @ RequestTrackDevice(`groupId`, deviceId, replyTo) =>
        deviceIdToActor.get(deviceId) match {
          case Some(deviceActor) =>
            replyTo ! DeviceRegistered(deviceActor)
          case None =>
            context.log.info("Creating device actor for {}", trackMsg.deviceId)
            val deviceActor = context.spawn(Device(groupId, deviceId), s"device-$deviceId")
+           context.watchWith(deviceActor, DeviceTerminated(deviceActor, groupId, deviceId))
            deviceIdToActor += deviceId -> deviceActor
            replyTo ! DeviceRegistered(deviceActor)
        }
        this

      case RequestTrackDevice(gId, _, _) =>
+       context.log.warn2("Ignoring TrackDevice request for {}. This actor is responsible for {}.", gId, groupId)
        this

Roiocam avatar May 07 '24 03:05 Roiocam