{"action":"created","issue":{"url":"https://api.github.com/repos/akka/akka/issues/18945","labels_url":"https://api.github.com/repos/akka/akka/issues/18945/labels{/name}","comments_url":"https://api.github.com/repos/akka/akka/issues/18945/comments","events_url":"https://api.github.com/repos/akka/akka/issues/18945/events","html_url":"https://github.com/akka/akka/issues/18945","id":117223990,"number":18945,"title":"[akka-cluster-sharding] ShardRegion doesn't kill shard actors on HandOff","user":{"login":"msosnicki","id":6181670,"avatar_url":"https://avatars.githubusercontent.com/u/6181670?v=3","gravatar_id":"","url":"https://api.github.com/users/msosnicki","html_url":"https://github.com/msosnicki","followers_url":"https://api.github.com/users/msosnicki/followers","following_url":"https://api.github.com/users/msosnicki/following{/other_user}","gists_url":"https://api.github.com/users/msosnicki/gists{/gist_id}","starred_url":"https://api.github.com/users/msosnicki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/msosnicki/subscriptions","organizations_url":"https://api.github.com/users/msosnicki/orgs","repos_url":"https://api.github.com/users/msosnicki/repos","events_url":"https://api.github.com/users/msosnicki/events{/privacy}","received_events_url":"https://api.github.com/users/msosnicki/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/akka/akka/labels/1%20-%20triaged","name":"1 - triaged","color":"5319e7"},{"url":"https://api.github.com/repos/akka/akka/labels/bug","name":"bug","color":"e11d21"},{"url":"https://api.github.com/repos/akka/akka/labels/t:cluster-tools","name":"t:cluster-tools","color":"CCCCCC"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/akka/akka/milestones/60","html_url":"https://github.com/akka/akka/milestones/2.4.1","labels_url":"https://api.github.com/repos/akka/akka/milestones/60/labels","id":1329566,"number":60,"title":"2.4.1","description":"","creator":{"login":"patriknw","id":336161,"avatar_url":"https://avatars.githubusercontent.com/u/336161?v=3","gravatar_id":"","url":"https://api.github.com/users/patriknw","html_url":"https://github.com/patriknw","followers_url":"https://api.github.com/users/patriknw/followers","following_url":"https://api.github.com/users/patriknw/following{/other_user}","gists_url":"https://api.github.com/users/patriknw/gists{/gist_id}","starred_url":"https://api.github.com/users/patriknw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/patriknw/subscriptions","organizations_url":"https://api.github.com/users/patriknw/orgs","repos_url":"https://api.github.com/users/patriknw/repos","events_url":"https://api.github.com/users/patriknw/events{/privacy}","received_events_url":"https://api.github.com/users/patriknw/received_events","type":"User","site_admin":false},"open_issues":17,"closed_issues":22,"state":"open","created_at":"2015-09-29T17:38:06Z","updated_at":"2015-11-18T14:31:03Z","due_on":null,"closed_at":null},"comments":11,"created_at":"2015-11-16T21:38:43Z","updated_at":"2015-11-21T16:17:19Z","closed_at":null,"body":"Hi,\r\n\r\nThis is a follow-up from the topic that can be found [here] (https://groups.google.com/forum/#!topic/akka-user/AF8P9i_MlUY) (you can skip the first post). \r\n\r\nTo summarize, when ShardRegion receives the *HandOff(shard)* message, it should stop all the entities for that shard. But it makes the decision based on this fragment:\r\n```scala  \r\nif (shards.contains(shard)) {\r\n   handingOff += shards(shard)\r\n   shards(shard) forward msg\r\n} else\r\n   sender() ! ShardStopped(shard)\r\n```\r\nThe *shards* map however, doesn't necessarily have all the shards in that ShardRegion, because this property is updated only from the constructor of Shards (*remember-entities=off*), of after successful recovery of a PersistenceShard (*remember-entities=on*).\r\nIn both cases it leaves a small gap (the problem is much bigger issue with PersistentShard though, because the recovery times might be significant), during which when receiving HandOff message will not cause the Shards to be stopped (the *ShardStopped* is sent immidiately without forwarding HandOff to a shard).\r\nThis leads to situations, where you can have multiple, same entities running in the same cluster.\r\n\r\nDo you think that updating atomically both *shards* and *shardsByRef* would solve the problem (for example in the *getShard* method)? Or is the current behaviour valid for some scenarios that I'm missing here?\r\n\r\nCheers,\r\nMarcin"},"comment":{"url":"https://api.github.com/repos/akka/akka/issues/comments/158659537","html_url":"https://github.com/akka/akka/issues/18945#issuecomment-158659537","issue_url":"https://api.github.com/repos/akka/akka/issues/18945","id":158659537,"user":{"login":"ktoso","id":120979,"avatar_url":"https://avatars.githubusercontent.com/u/120979?v=3","gravatar_id":"","url":"https://api.github.com/users/ktoso","html_url":"https://github.com/ktoso","followers_url":"https://api.github.com/users/ktoso/followers","following_url":"https://api.github.com/users/ktoso/following{/other_user}","gists_url":"https://api.github.com/users/ktoso/gists{/gist_id}","starred_url":"https://api.github.com/users/ktoso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ktoso/subscriptions","organizations_url":"https://api.github.com/users/ktoso/orgs","repos_url":"https://api.github.com/users/ktoso/repos","events_url":"https://api.github.com/users/ktoso/events{/privacy}","received_events_url":"https://api.github.com/users/ktoso/received_events","type":"User","site_admin":false},"created_at":"2015-11-21T16:17:19Z","updated_at":"2015-11-21T16:17:19Z","body":"Thanks a lot for the PR @msosnicki!"}}