{"action":"created","issue":{"url":"https://api.github.com/repos/robolectric/robolectric/issues/3211","repository_url":"https://api.github.com/repos/robolectric/robolectric","labels_url":"https://api.github.com/repos/robolectric/robolectric/issues/3211/labels{/name}","comments_url":"https://api.github.com/repos/robolectric/robolectric/issues/3211/comments","events_url":"https://api.github.com/repos/robolectric/robolectric/issues/3211/events","html_url":"https://github.com/robolectric/robolectric/pull/3211","id":239075449,"number":3211,"title":"Fixes 1986","user":{"login":"matthewhubblerose","id":7779758,"avatar_url":"https://avatars0.githubusercontent.com/u/7779758?v=3","gravatar_id":"","url":"https://api.github.com/users/matthewhubblerose","html_url":"https://github.com/matthewhubblerose","followers_url":"https://api.github.com/users/matthewhubblerose/followers","following_url":"https://api.github.com/users/matthewhubblerose/following{/other_user}","gists_url":"https://api.github.com/users/matthewhubblerose/gists{/gist_id}","starred_url":"https://api.github.com/users/matthewhubblerose/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthewhubblerose/subscriptions","organizations_url":"https://api.github.com/users/matthewhubblerose/orgs","repos_url":"https://api.github.com/users/matthewhubblerose/repos","events_url":"https://api.github.com/users/matthewhubblerose/events{/privacy}","received_events_url":"https://api.github.com/users/matthewhubblerose/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-06-28T07:27:02Z","updated_at":"2017-06-28T07:36:46Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/robolectric/robolectric/pulls/3211","html_url":"https://github.com/robolectric/robolectric/pull/3211","diff_url":"https://github.com/robolectric/robolectric/pull/3211.diff","patch_url":"https://github.com/robolectric/robolectric/pull/3211.patch"},"body":"Fixes #1986\r\n\r\n### Overview\r\n\r\nWhen running tests on Linux platforms, occasionally tests would fail due to an exception like the following:\r\n```\r\njava.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.AssertionError: DB[46] will not dispose from a non-confining thread\r\n```\r\n\r\nThe `AssertionError` is thrown from the sqlite4java library when an attempt was made to close a connection on a different thread to the one it was opened on. All interaction with connections and statements are done by submitting `Callable`s to the `dbExecutor` `ExecutorService`, which is a single thread executor.\r\n\r\nI believe the issue occurs as there is a race condition in the reset function, which used to look like this:\r\n```\r\npublic void reset() {\r\n  for (long connectionPtr : connectionsMap.keySet()) {\r\n    close(connectionPtr);\r\n  }\r\n  dbExecutor.shutdown();\r\n  try {\r\n    dbExecutor.awaitTermination(30, TimeUnit.SECONDS);\r\n  } catch (InterruptedException e) {\r\n    throw new RuntimeException(e);\r\n  }\r\n  dbExecutor = Executors.newSingleThreadExecutor();\r\n  connectionsMap.clear();\r\n  statementsMap.clear();\r\n}\r\n```\r\n\r\n If a connection was opened between the last call to `close(connectionPtr)` and this line: `dbExecutor = Executors.newSingleThreadExecutor()`, then a connection would have been opened on the old thread, and any attempt to close it would be on a new thread.\r\n\r\n### Proposed Changes\r\n\r\nThe fix is to synchronize all access to anything that interacts with `dbExecutor`, `connectionsMap` and `statementsMap`. A key implication of this is that any work submitted to the dbExecutor must not try to synchronize on the lock, as it will cause a deadlock.\r\n\r\nAs well as this `useInMemoryDatabase ` has been made an `AtomicBoolean` as it was written to on multiple thread and read on the `dbExecutor` thread. Also when connections are closed they now get removed from `connectionsMap`"},"comment":{"url":"https://api.github.com/repos/robolectric/robolectric/issues/comments/311581522","html_url":"https://github.com/robolectric/robolectric/pull/3211#issuecomment-311581522","issue_url":"https://api.github.com/repos/robolectric/robolectric/issues/3211","id":311581522,"user":{"login":"matthewhubblerose","id":7779758,"avatar_url":"https://avatars0.githubusercontent.com/u/7779758?v=3","gravatar_id":"","url":"https://api.github.com/users/matthewhubblerose","html_url":"https://github.com/matthewhubblerose","followers_url":"https://api.github.com/users/matthewhubblerose/followers","following_url":"https://api.github.com/users/matthewhubblerose/following{/other_user}","gists_url":"https://api.github.com/users/matthewhubblerose/gists{/gist_id}","starred_url":"https://api.github.com/users/matthewhubblerose/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthewhubblerose/subscriptions","organizations_url":"https://api.github.com/users/matthewhubblerose/orgs","repos_url":"https://api.github.com/users/matthewhubblerose/repos","events_url":"https://api.github.com/users/matthewhubblerose/events{/privacy}","received_events_url":"https://api.github.com/users/matthewhubblerose/received_events","type":"User","site_admin":false},"created_at":"2017-06-28T07:36:46Z","updated_at":"2017-06-28T07:36:46Z","body":"I've managed to run the tests on my machine, but I've been unable to use a locally built snapshot version to test with on my project. This **should not** be merged until it's been tested with some projects.\r\n\r\nIs anyone able to provide some instructions on getting a snapshot version built that can be included from a project. Including the snapshot version I built locally results in this gradle error:\r\n\r\n```\r\nError:\r\n\r\nCould not find org.robolectric:framework:3.4-SNAPSHOT.\r\nRequired by:\r\n    project :myproject > org.robolectric:robolectric:3.4-SNAPSHOT\r\n```"}}
{"actor":{"display_login":"matthewhubblerose"}}