cheerfulstoic / ecto_watch

EctoWatch allows you to easily get notifications about database changes directly from PostgreSQL.
175 stars 5 forks source link

failed to start child: EctoWatch #9

Closed barrelltech closed 3 weeks ago

barrelltech commented 1 month ago

When running my tests, I'm periodically receiving the following error:

** (Mix) Could not start application phrasing: MyApp.Application.start(:normal, []) returned an error: shutdown: failed to start child: EctoWatch
    ** (EXIT) shutdown: failed to start child: EctoWatch.WatcherSupervisor
        ** (EXIT) shutdown: failed to start child: :ew_inserted_for_my_app_material_media
            ** (EXIT) an exception was raised:
                ** (Postgrex.Error) ERROR XX000 (internal_error) tuple concurrently updated
                    (ecto_sql 3.11.3) lib/ecto/adapters/sql.ex:1054: Ecto.Adapters.SQL.raise_sql_call_error/1
                    (ecto_watch 0.5.3) lib/ecto_watch/watcher_server.ex:80: EctoWatch.WatcherServer.init/1
                    (stdlib 5.2.3) gen_server.erl:980: :gen_server.init_it/2
                    (stdlib 5.2.3) gen_server.erl:935: :gen_server.init_it/6
                    (stdlib 5.2.3) proc_lib.erl:241: :proc_lib.init_p_do_apply/3

I have not looked into this yet, likely just have to turn off EctoWatch for tests. I'll try to report back with the solution when I have time to look into it! For now rerunning the tests works (fails ~1/5 times)

cheerfulstoic commented 1 month ago

🤔 Interesting, I wonder (just for debugging purposes) if making your test run synchronous (using use ExUnit.Case, async: false) fixes the problem?

I also found this: https://stackoverflow.com/questions/19382284/postgresql-error-tuple-concurrently-updated

So maybe the error can have something to do with transactions or creating functions...

There's also this: https://dba.stackexchange.com/questions/160954/postgres-error-tuple-concurrently-updated

I can see that the error is coming from EctoWatch.WatcherServer.init, so it's happening as the watcher is being created and I think in the CREATE OR REPLACE FUNCTION call. I wonder if it's because a number of tests are trying to create functions at the same time. Maybe if this was inside a transaction (?)

cheerfulstoic commented 3 weeks ago

I guess that this is solved in #14 / 0.7.0, but let me know if not