{"action":"created","issue":{"url":"https://api.github.com/repos/elixir-lang/ecto/issues/1319","repository_url":"https://api.github.com/repos/elixir-lang/ecto","labels_url":"https://api.github.com/repos/elixir-lang/ecto/issues/1319/labels{/name}","comments_url":"https://api.github.com/repos/elixir-lang/ecto/issues/1319/comments","events_url":"https://api.github.com/repos/elixir-lang/ecto/issues/1319/events","html_url":"https://github.com/elixir-lang/ecto/issues/1319","id":141036438,"number":1319,"title":"\"(RuntimeError) cannot find ownership process\" error for channel tests in Phoenix (phoenix_ecto: 3.0.0-beta.2)","user":{"login":"pdawczak","id":601110,"avatar_url":"https://avatars.githubusercontent.com/u/601110?v=3","gravatar_id":"","url":"https://api.github.com/users/pdawczak","html_url":"https://github.com/pdawczak","followers_url":"https://api.github.com/users/pdawczak/followers","following_url":"https://api.github.com/users/pdawczak/following{/other_user}","gists_url":"https://api.github.com/users/pdawczak/gists{/gist_id}","starred_url":"https://api.github.com/users/pdawczak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pdawczak/subscriptions","organizations_url":"https://api.github.com/users/pdawczak/orgs","repos_url":"https://api.github.com/users/pdawczak/repos","events_url":"https://api.github.com/users/pdawczak/events{/privacy}","received_events_url":"https://api.github.com/users/pdawczak/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-03-15T16:58:30Z","updated_at":"2016-05-06T07:40:53Z","closed_at":"2016-03-16T07:51:27Z","body":"### Environment\r\n\r\n* Elixir version (elixir -v): Elixir 1.2.1\r\n* Database and version (PostgreSQL 9.4, MongoDB 3.2, etc.): psql (PostgreSQL) 9.4.4\r\n* Ecto version (mix deps):\r\n\r\n```\r\n➜  fire_slack git:(pd-channels) ✗ mix deps\r\n* connection 1.0.2 (Hex package) (mix)\r\n  locked at 1.0.2 (connection)\r\n  ok\r\n* fs 0.9.1 (Hex package) (rebar)\r\n  locked at 0.9.2 (fs)\r\n  ok\r\n* gettext 0.10.0 (Hex package) (mix)\r\n  locked at 0.10.0 (gettext)\r\n  ok\r\n* ranch 1.2.1 (Hex package) (rebar)\r\n  locked at 1.2.1 (ranch)\r\n  ok\r\n* poolboy 1.5.1 (Hex package) (rebar)\r\n  locked at 1.5.1 (poolboy)\r\n  ok\r\n* decimal 1.1.1 (Hex package) (mix)\r\n  locked at 1.1.1 (decimal)\r\n  ok\r\n* poison 2.1.0 (Hex package) (mix)\r\n  locked at 2.1.0 (poison)\r\n  ok\r\n* db_connection 0.2.4 (Hex package) (mix)\r\n  locked at 0.2.4 (db_connection)\r\n  ok\r\n* cowlib 1.0.2 (Hex package) (rebar)\r\n  locked at 1.0.2 (cowlib)\r\n  ok\r\n* cowboy 1.0.4 (Hex package) (rebar)\r\n  locked at 1.0.4 (cowboy)\r\n  ok\r\n* plug 1.1.2 (Hex package) (mix)\r\n  locked at 1.1.2 (plug)\r\n  ok\r\n* phoenix_html 2.5.1 (Hex package) (mix)\r\n  locked at 2.5.1 (phoenix_html)\r\n  ok\r\n* phoenix 1.1.4 (Hex package) (mix)\r\n  locked at 1.1.4 (phoenix)\r\n  ok\r\n* phoenix_live_reload 1.0.3 (Hex package) (mix)\r\n  locked at 1.0.3 (phoenix_live_reload)\r\n  ok\r\n* postgrex 0.11.1 (Hex package) (mix)\r\n  locked at 0.11.1 (postgrex)\r\n  ok\r\n* ecto 2.0.0-beta.2 (Hex package) (mix)\r\n  locked at 2.0.0-beta.2 (ecto)\r\n  ok\r\n* phoenix_ecto 3.0.0-beta.2 (Hex package) (mix)\r\n  locked at 3.0.0-beta.2 (phoenix_ecto)\r\n  ok\r\n```\r\n\r\n* Operating system: MacOS X 10.10.5\r\n\r\n## Description\r\n\r\nI've taken the steps from section [Using Ecto 2.0 in Phoenix projects](http://blog.plataformatec.com.br/2016/02/ecto-2-0-0-beta-0-is-out/) to try out the new version of Ecto in Phoenix application.\r\n\r\nWhen running the tests they fail for _channels_ (please note, the tests were automatically generated for `mix phoenix.gen.channel`):\r\n\r\n```\r\n➜  fire_slack git:(pd-channels) ✗ mix test\r\n....\r\n\r\n  1) test shout broadcasts to channel:lobby (FS.ChannelChannelTest)\r\n     test/channels/channel_channel_test.exs:19\r\n     ** (EXIT from #PID<0.294.0>) an exception was raised:\r\n         ** (RuntimeError) cannot find ownership process for #PID<0.296.0>.\r\n\r\n     When using ownership, you must manage connections in one\r\n     of the three ways:\r\n\r\n       * By explicitly checking out a connection\r\n       * By explicitly allowing a spawned process\r\n       * By running the pool in shared mode\r\n\r\n     The first two options require every new process to explicitly\r\n     check a connection out or be allowed.\r\n\r\n     If you are reading this error, it means you have not done one\r\n     of the steps above or that the owner process has crashed.\r\n\r\n             (db_connection) lib/db_connection.ex:817: DBConnection.checkout/2\r\n             (db_connection) lib/db_connection.ex:717: DBConnection.run/3\r\n             (db_connection) lib/db_connection.ex:535: DBConnection.prepare_execute/4\r\n             (ecto) lib/ecto/adapters/sql.ex:369: Ecto.Adapters.SQL.execute_and_cache/7\r\n             (ecto) lib/ecto/repo/queryable.ex:127: Ecto.Repo.Queryable.execute/5\r\n             (ecto) lib/ecto/repo/queryable.ex:40: Ecto.Repo.Queryable.all/4\r\n             (fire_slack) web/channels/channel_channel.ex:35: FS.ChannelChannel.handle_info/2\r\n             (phoenix) lib/phoenix/channel/server.ex:242: Phoenix.Channel.Server.handle_info/2\r\n             (stdlib) gen_server.erl:615: :gen_server.try_dispatch/4\r\n             (stdlib) gen_server.erl:681: :gen_server.handle_msg/5\r\n             (stdlib) proc_lib.erl:240: :proc_lib.init_p_do_apply/3\r\n\r\n\r\n\r\n  2) test ping replies with status ok (FS.ChannelChannelTest)\r\n     test/channels/channel_channel_test.exs:14\r\n     ** (EXIT from #PID<0.297.0>) an exception was raised:\r\n         ** (RuntimeError) cannot find ownership process for #PID<0.299.0>.\r\n\r\n     When using ownership, you must manage connections in one\r\n     of the three ways:\r\n\r\n       * By explicitly checking out a connection\r\n       * By explicitly allowing a spawned process\r\n       * By running the pool in shared mode\r\n\r\n     The first two options require every new process to explicitly\r\n     check a connection out or be allowed.\r\n\r\n     If you are reading this error, it means you have not done one\r\n     of the steps above or that the owner process has crashed.\r\n\r\n             (db_connection) lib/db_connection.ex:817: DBConnection.checkout/2\r\n             (db_connection) lib/db_connection.ex:717: DBConnection.run/3\r\n             (db_connection) lib/db_connection.ex:535: DBConnection.prepare_execute/4\r\n             (ecto) lib/ecto/adapters/sql.ex:369: Ecto.Adapters.SQL.execute_and_cache/7\r\n             (ecto) lib/ecto/repo/queryable.ex:127: Ecto.Repo.Queryable.execute/5\r\n             (ecto) lib/ecto/repo/queryable.ex:40: Ecto.Repo.Queryable.all/4\r\n             (fire_slack) web/channels/channel_channel.ex:35: FS.ChannelChannel.handle_info/2\r\n             (phoenix) lib/phoenix/channel/server.ex:242: Phoenix.Channel.Server.handle_info/2\r\n             (stdlib) gen_server.erl:615: :gen_server.try_dispatch/4\r\n             (stdlib) gen_server.erl:681: :gen_server.handle_msg/5\r\n             (stdlib) proc_lib.erl:240: :proc_lib.init_p_do_apply/3\r\n\r\n\r\n\r\n  3) test broadcasts are pushed to the client (FS.ChannelChannelTest)\r\n     test/channels/channel_channel_test.exs:24\r\n     ** (EXIT from #PID<0.300.0>) an exception was raised:\r\n         ** (RuntimeError) cannot find ownership process for #PID<0.302.0>.\r\n\r\n     When using ownership, you must manage connections in one\r\n     of the three ways:\r\n\r\n       * By explicitly checking out a connection\r\n       * By explicitly allowing a spawned process\r\n       * By running the pool in shared mode\r\n\r\n     The first two options require every new process to explicitly\r\n     check a connection out or be allowed.\r\n\r\n     If you are reading this error, it means you have not done one\r\n     of the steps above or that the owner process has crashed.\r\n\r\n             (db_connection) lib/db_connection.ex:817: DBConnection.checkout/2\r\n             (db_connection) lib/db_connection.ex:717: DBConnection.run/3\r\n             (db_connection) lib/db_connection.ex:535: DBConnection.prepare_execute/4\r\n             (ecto) lib/ecto/adapters/sql.ex:369: Ecto.Adapters.SQL.execute_and_cache/7\r\n             (ecto) lib/ecto/repo/queryable.ex:127: Ecto.Repo.Queryable.execute/5\r\n             (ecto) lib/ecto/repo/queryable.ex:40: Ecto.Repo.Queryable.all/4\r\n             (fire_slack) web/channels/channel_channel.ex:35: FS.ChannelChannel.handle_info/2\r\n             (phoenix) lib/phoenix/channel/server.ex:242: Phoenix.Channel.Server.handle_info/2\r\n             (stdlib) gen_server.erl:615: :gen_server.try_dispatch/4\r\n             (stdlib) gen_server.erl:681: :gen_server.handle_msg/5\r\n             (stdlib) proc_lib.erl:240: :proc_lib.init_p_do_apply/3\r\n\r\n..16:49:47.112 [error] GenServer #PID<0.296.0> terminating\r\n** (RuntimeError) cannot find ownership process for #PID<0.296.0>.\r\n\r\nWhen using ownership, you must manage connections in one\r\nof the three ways:\r\n\r\n  * By explicitly checking out a connection\r\n  * By explicitly allowing a spawned process\r\n  * By running the pool in shared mode\r\n\r\nThe first two options require every new process to explicitly\r\ncheck a connection out or be allowed.\r\n\r\nIf you are reading this error, it means you have not done one\r\nof the steps above or that the owner process has crashed.\r\n\r\n    (db_connection) lib/db_connection.ex:817: DBConnection.checkout/2\r\n    (db_connection) lib/db_connection.ex:717: DBConnection.run/3\r\n    (db_connection) lib/db_connection.ex:535: DBConnection.prepare_execute/4\r\n    (ecto) lib/ecto/adapters/sql.ex:369: Ecto.Adapters.SQL.execute_and_cache/7\r\n    (ecto) lib/ecto/repo/queryable.ex:127: Ecto.Repo.Queryable.execute/5\r\n    (ecto) lib/ecto/repo/queryable.ex:40: Ecto.Repo.Queryable.all/4\r\n    (fire_slack) web/channels/channel_channel.ex:35: FS.ChannelChannel.handle_info/2\r\n    (phoenix) lib/phoenix/channel/server.ex:242: Phoenix.Channel.Server.handle_info/2\r\n    (stdlib) gen_server.erl:615: :gen_server.try_dispatch/4\r\n    (stdlib) gen_server.erl:681: :gen_server.handle_msg/5\r\n    (stdlib) proc_lib.erl:240: :proc_lib.init_p_do_apply/3\r\n16:49:47.113 [error] GenServer #PID<0.299.0> terminating\r\n** (RuntimeError) cannot find ownership process for #PID<0.299.0>.\r\n\r\nWhen using ownership, you must manage connections in one\r\nof the three ways:\r\n\r\n  * By explicitly checking out a connection\r\n  * By explicitly allowing a spawned process\r\n  * By running the pool in shared mode\r\n\r\nThe first two options require every new process to explicitly\r\ncheck a connection out or be allowed.\r\n\r\nIf you are reading this error, it means you have not done one\r\nof the steps above or that the owner process has crashed.\r\n\r\n    (db_connection) lib/db_connection.ex:817: DBConnection.checkout/2\r\n    (db_connection) lib/db_connection.ex:717: DBConnection.run/3\r\n    (db_connection) lib/db_connection.ex:535: DBConnection.prepare_execute/4\r\n    (ecto) lib/ecto/adapters/sql.ex:369: Ecto.Adapters.SQL.execute_and_cache/7\r\n    (ecto) lib/ecto/repo/queryable.ex:127: Ecto.Repo.Queryable.execute/5\r\n    (ecto) lib/ecto/repo/queryable.ex:40: Ecto.Repo.Queryable.all/4\r\n    (fire_slack) web/channels/channel_channel.ex:35: FS.ChannelChannel.handle_info/2\r\n    (phoenix) lib/phoenix/channel/server.ex:242: Phoenix.Channel.Server.handle_info/2\r\n    (stdlib) gen_server.erl:615: :gen_server.try_dispatch/4\r\n    (stdlib) gen_server.erl:681: :gen_server.handle_msg/5\r\n    (stdlib) proc_lib.erl:240: :proc_lib.init_p_do_apply/3\r\n16:49:47.113 [error] GenServer #PID<0.302.0> terminating\r\n** (RuntimeError) cannot find ownership process for #PID<0.302.0>.\r\n\r\nWhen using ownership, you must manage connections in one\r\nof the three ways:\r\n\r\n  * By explicitly checking out a connection\r\n  * By explicitly allowing a spawned process\r\n  * By running the pool in shared mode\r\n\r\nThe first two options require every new process to explicitly\r\ncheck a connection out or be allowed.\r\n\r\nIf you are reading this error, it means you have not done one\r\nof the steps above or that the owner process has crashed.\r\n\r\n    (db_connection) lib/db_connection.ex:817: DBConnection.checkout/2\r\n    (db_connection) lib/db_connection.ex:717: DBConnection.run/3\r\n    (db_connection) lib/db_connection.ex:535: DBConnection.prepare_execute/4\r\n    (ecto) lib/ecto/adapters/sql.ex:369: Ecto.Adapters.SQL.execute_and_cache/7\r\n    (ecto) lib/ecto/repo/queryable.ex:127: Ecto.Repo.Queryable.execute/5\r\n    (ecto) lib/ecto/repo/queryable.ex:40: Ecto.Repo.Queryable.all/4\r\n    (fire_slack) web/channels/channel_channel.ex:35: FS.ChannelChannel.handle_info/2\r\n    (phoenix) lib/phoenix/channel/server.ex:242: Phoenix.Channel.Server.handle_info/2\r\n    (stdlib) gen_server.erl:615: :gen_server.try_dispatch/4\r\n    (stdlib) gen_server.erl:681: :gen_server.handle_msg/5\r\n    (stdlib) proc_lib.erl:240: :proc_lib.init_p_do_apply/3\r\n........\r\n\r\nFinished in 0.4 seconds (0.3s on load, 0.1s on tests)\r\n17 tests, 3 failures\r\n\r\nRandomized with seed 46676\r\n```\r\n\r\nFiles changed after updating Ecto:\r\n\r\n**test/test_helper.exs**\r\n\r\n```elixir\r\nExUnit.start\r\n\r\nMix.Task.run \"ecto.create\", ~w(-r FS.Repo --quiet)\r\nMix.Task.run \"ecto.migrate\", ~w(-r FS.Repo --quiet)\r\nEcto.Adapters.SQL.Sandbox.mode(FS.Repo, :manual)\r\n```\r\n\r\n**test/support/channel_case.exs**\r\n\r\n```elixir\r\ndefmodule FS.ChannelCase do\r\n  @moduledoc \"\"\"\r\n  This module defines the test case to be used by\r\n  channel tests.\r\n\r\n  Such tests rely on `Phoenix.ChannelTest` and also\r\n  imports other functionality to make it easier\r\n  to build and query models.\r\n\r\n  Finally, if the test case interacts with the database,\r\n  it cannot be async. For this reason, every test runs\r\n  inside a transaction which is reset at the beginning\r\n  of the test unless the test case is marked as async.\r\n  \"\"\"\r\n\r\n  use ExUnit.CaseTemplate\r\n\r\n  using do\r\n    quote do\r\n      # Import conveniences for testing with channels\r\n      use Phoenix.ChannelTest\r\n\r\n      alias FS.Repo\r\n      import Ecto\r\n      import Ecto.Changeset\r\n      import Ecto.Query, only: [from: 1, from: 2]\r\n\r\n\r\n      # The default endpoint for testing\r\n      @endpoint FS.Endpoint\r\n    end\r\n  end\r\n\r\n  setup tags do\r\n    :ok = Ecto.Adapters.SQL.Sandbox.checkout(FS.Repo)\r\n  end\r\nend\r\n```\r\n\r\nAll the rest of the tests (controllers/models) seem to be fine. Please, let me know if I can provide any more information. \r\n\r\nThanks!"},"comment":{"url":"https://api.github.com/repos/elixir-lang/ecto/issues/comments/217371833","html_url":"https://github.com/elixir-lang/ecto/issues/1319#issuecomment-217371833","issue_url":"https://api.github.com/repos/elixir-lang/ecto/issues/1319","id":217371833,"user":{"login":"josevalim","id":9582,"avatar_url":"https://avatars.githubusercontent.com/u/9582?v=3","gravatar_id":"","url":"https://api.github.com/users/josevalim","html_url":"https://github.com/josevalim","followers_url":"https://api.github.com/users/josevalim/followers","following_url":"https://api.github.com/users/josevalim/following{/other_user}","gists_url":"https://api.github.com/users/josevalim/gists{/gist_id}","starred_url":"https://api.github.com/users/josevalim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josevalim/subscriptions","organizations_url":"https://api.github.com/users/josevalim/orgs","repos_url":"https://api.github.com/users/josevalim/repos","events_url":"https://api.github.com/users/josevalim/events{/privacy}","received_events_url":"https://api.github.com/users/josevalim/received_events","type":"User","site_admin":false},"created_at":"2016-05-06T07:40:53Z","updated_at":"2016-05-06T07:40:53Z","body":"Yes, that's how ownership works. Check out the docs for the SQL Sandbox\npool, it covers such scenarios and how to solve them.\n\nOn Friday, May 6, 2016, Hubert Łępicki <notifications@github.com> wrote:\n\n> I just wanted to let you know that this is not only issue with channels.\n> This looks like it is an issue with any process in an app other than the\n> default ones created by Phoenix.\n>\n> For example, if you have a background job worker, that is a supervised\n> GenServer (for example) and it tries to perform some operations on\n> database, the above error will appear.\n>\n> —\n> You are receiving this because you were mentioned.\n> Reply to this email directly or view it on GitHub\n> <https://github.com/elixir-lang/ecto/issues/1319#issuecomment-217368018>\n>\n\n\n-- \n\n\n*José Valimwww.plataformatec.com.br\n<http://www.plataformatec.com.br/>Founder and Director of R&D*\n"}}