{"action":"created","issue":{"url":"https://api.github.com/repos/dnvriend/akka-persistence-inmemory/issues/22","repository_url":"https://api.github.com/repos/dnvriend/akka-persistence-inmemory","labels_url":"https://api.github.com/repos/dnvriend/akka-persistence-inmemory/issues/22/labels{/name}","comments_url":"https://api.github.com/repos/dnvriend/akka-persistence-inmemory/issues/22/comments","events_url":"https://api.github.com/repos/dnvriend/akka-persistence-inmemory/issues/22/events","html_url":"https://github.com/dnvriend/akka-persistence-inmemory/pull/22","id":138097709,"number":22,"title":"fix race condition in cleanup helper","user":{"login":"acjay","id":1256382,"avatar_url":"https://avatars.githubusercontent.com/u/1256382?v=3","gravatar_id":"","url":"https://api.github.com/users/acjay","html_url":"https://github.com/acjay","followers_url":"https://api.github.com/users/acjay/followers","following_url":"https://api.github.com/users/acjay/following{/other_user}","gists_url":"https://api.github.com/users/acjay/gists{/gist_id}","starred_url":"https://api.github.com/users/acjay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/acjay/subscriptions","organizations_url":"https://api.github.com/users/acjay/orgs","repos_url":"https://api.github.com/users/acjay/repos","events_url":"https://api.github.com/users/acjay/events{/privacy}","received_events_url":"https://api.github.com/users/acjay/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-03T07:22:52Z","updated_at":"2016-03-03T11:32:09Z","closed_at":"2016-03-03T11:32:03Z","pull_request":{"url":"https://api.github.com/repos/dnvriend/akka-persistence-inmemory/pulls/22","html_url":"https://github.com/dnvriend/akka-persistence-inmemory/pull/22","diff_url":"https://github.com/dnvriend/akka-persistence-inmemory/pull/22.diff","patch_url":"https://github.com/dnvriend/akka-persistence-inmemory/pull/22.patch"},"body":"I cut-and-pasted `cleanup` into my own project and was experiencing test failures about 50% of the time. With the rearrangement, I've run my tests 25 times in a row without any failures. (This is using v1.2.1 of this library, to prevent the error mentioned https://github.com/dnvriend/akka-persistence-inmemory/issues/21#issuecomment-191596529.)\r\n\r\nI haven't been able to convince myself of exactly where the race is, so I don't think I can write a test to replicate the problem. So feel free to not merge if that makes you uncomfortable. \r\n\r\nIn case it's helpful, when it errored, I saw the following in the logging/diagnostic printing:\r\n\r\n```\r\n[info] - must work correct if ValidationResponse is sent directly back to the log\r\nInstantiating log\r\nLog instantiated.\r\nLogs: Map(test-12 -> Actor[akka://default/user/$p/test-12#1823397508])\r\n[DEBUG] [03/03/2016 01:26:04.719] [default-akka.persistence.dispatchers.default-plugin-dispatcher-6] [akka://default/system/inmemory-snapshot-store] Loading for persistenceId: domainEvents:test-12, criteria: SnapshotSelectionCriteria(9223372036854775807,9223372036854775807,0,0)\r\n[DEBUG] [03/03/2016 01:26:04.720] [default-akka.persistence.dispatchers.default-plugin-dispatcher-5] [akka://default/system/inmemory-journal] Async read for highest sequence number for processorId: domainEvents:test-12 (hint, seek from  nr: 0)\r\nRecovery completed\r\nLogs: Map(test-12 -> Actor[akka://default/user/$p/test-12#1823397508])\r\nLogs: Map(test-12 -> Actor[akka://default/user/$p/test-12#1823397508])\r\nLogs: Map(test-12 -> Actor[akka://default/user/$p/test-12#1823397508])\r\nLogs: Map(test-12 -> Actor[akka://default/user/$p/test-12#1823397508])\r\nQueryEvents (data: EventLogData(None,List(Timestamped(TestEvent1(test-12),2016-03-03T01:26:04.721-05:00), Timestamped(TestEvent2(test-12),2016-03-03T01:26:04.724-05:00))))\r\nLogs: Map(test-12 -> Actor[akka://default/user/$p/test-12#1823397508])\r\nLog terminated. Logs: Map()\r\n[INFO] [03/03/2016 01:26:04.742] [default-akka.actor.default-dispatcher-4] [akka://default/user/$p/test-12] Message [net.artsy.atomic.AtomicEventStore$QueryEvents$] from Actor[akka://default/system/testActor-1#-1378593046] to Actor[akka://default/user/$p/test-12#1823397508] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.\r\n[info] - must regenerate dead log actor that had two events, with state intact *** FAILED ***\r\n[info]   java.lang.AssertionError: assertion failed: expected: list of one event but got unexpected message Result(false,TestEvent2(test-4),List(Timestamped(TestEvent1(test-4),2016-03-03T01:26:04.651-05:00)),Some(Timeout))\r\n[info]   at scala.Predef$.assert(Predef.scala:165)\r\n[info]   at akka.testkit.TestKitBase$class.expectMsgPF(TestKit.scala:369)\r\n[info]   at net.artsy.atomic.AtomicEventStoreSpec.expectMsgPF(AtomicEventStoreSpec.scala:15)\r\n[info]   at net.artsy.atomic.AtomicEventStoreSpec$$anonfun$3$$anonfun$apply$mcV$sp$19$$anonfun$apply$mcV$sp$20.apply$mcV$sp(AtomicEventStoreSpec.scala:431)\r\n[info]   at net.artsy.atomic.AtomicEventStoreSpec$$anonfun$3$$anonfun$apply$mcV$sp$19$$anonfun$apply$mcV$sp$20.apply(AtomicEventStoreSpec.scala:395)\r\n[info]   at net.artsy.atomic.AtomicEventStoreSpec$$anonfun$3$$anonfun$apply$mcV$sp$19$$anonfun$apply$mcV$sp$20.apply(AtomicEventStoreSpec.scala:395)\r\n[info]   at akka.testkit.TestKitBase$class.within(TestKit.scala:308)\r\n[info]   at net.artsy.atomic.AtomicEventStoreSpec.within(AtomicEventStoreSpec.scala:15)\r\n[info]   at akka.testkit.TestKitBase$class.within(TestKit.scala:322)\r\n[info]   at net.artsy.atomic.AtomicEventStoreSpec.within(AtomicEventStoreSpec.scala:15)\r\n[info]   ...\r\n[INFO] [03/03/2016 01:26:07.679] [default-akka.actor.default-dispatcher-7] [akka://default/user/$i] Message [akka.persistence.fsm.PersistentFSM$TimeoutMarker] from Actor[akka://default/user/$i#-1299734467] to Actor[akka://default/user/$i#-1299734467] was not delivered. [2] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.\r\n```"},"comment":{"url":"https://api.github.com/repos/dnvriend/akka-persistence-inmemory/issues/comments/191718771","html_url":"https://github.com/dnvriend/akka-persistence-inmemory/pull/22#issuecomment-191718771","issue_url":"https://api.github.com/repos/dnvriend/akka-persistence-inmemory/issues/22","id":191718771,"user":{"login":"dnvriend","id":4494623,"avatar_url":"https://avatars.githubusercontent.com/u/4494623?v=3","gravatar_id":"","url":"https://api.github.com/users/dnvriend","html_url":"https://github.com/dnvriend","followers_url":"https://api.github.com/users/dnvriend/followers","following_url":"https://api.github.com/users/dnvriend/following{/other_user}","gists_url":"https://api.github.com/users/dnvriend/gists{/gist_id}","starred_url":"https://api.github.com/users/dnvriend/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dnvriend/subscriptions","organizations_url":"https://api.github.com/users/dnvriend/orgs","repos_url":"https://api.github.com/users/dnvriend/repos","events_url":"https://api.github.com/users/dnvriend/events{/privacy}","received_events_url":"https://api.github.com/users/dnvriend/received_events","type":"User","site_admin":false},"created_at":"2016-03-03T11:32:09Z","updated_at":"2016-03-03T11:32:09Z","body":"Thanks!\r\n"}}