devsisters / shardcake

Sharding and location transparency for Scala
https://devsisters.github.io/shardcake/
Apache License 2.0
382 stars 29 forks source link

[Interruption] terminateEntity does not wait for graceful interruption to complete #83

Closed mattiamanzati closed 11 months ago

mattiamanzati commented 1 year ago

It seems like terminateEntity after sending the termination message to the queue does not wait for the created promise. That means that after the message is succefully delivered, the entity terminates immediatly without waiting for proper interruption.

Example written in typescript: https://github.com/mattiamanzati/shardcake/blob/dca200d6c6c3d10a18379355cc23c74fab6338cf/test/SampleTests.ts#L238-L290

Shard termination is handled fine instead, as all promises are awaited or timed out.

ghostdogpr commented 1 year ago

I don't think that is the case. When an entity is terminated with termination message, we run:

queue.offer(msg).exit.as(map.updated(entityId, (None, interruptionFiber)))

Which means we enqueue the termination message, then we update the entity map with None instead of the queue. As long as the value is None, we're not creating a new queue:

                     case Some((None, _)) =>
                       // the queue is shutting down, stash and retry
                       ZIO.succeed((p, map))

So we are indeed waiting for the entity to terminate.

mattiamanzati commented 11 months ago

Yeah can confirm it achieved the same result by fixing the wait for shutdown of already terminating entities. Thanks a lot!