cpursley / walex

Postgres change events (CDC) in Elixir
MIT License
276 stars 14 forks source link

It does not work on every server boot #20

Closed andreaseriksson closed 8 months ago

andreaseriksson commented 8 months ago

I have an issue that it does not work on every server boot in my dev environment. When it works, it works 100% and vice versa. My guess, some sort of race condition. The processes seem to be alive and seems to be the same in both scenarios.

dev.exs

config :tutorial, Tutorial.Repo,
  username: "postgres",
  password: "postgres",
  hostname: "localhost",
  database: "phx_tutorials_dev",
  stacktrace: true,
  show_sensitive_data_on_connection_error: true,
  pool_size: 10

config :tutorial, WalEx,
  hostname: "localhost",
  username: "postgres",
  password: "postgres",
  port: "5432",
  database: "phx_tutorials_dev",
  publication: "events",
  subscriptions: [:companies],
  modules: [Tutorial.CompanyEvent],
  name: Tutorial

I run Elixir 1.15.7 (compiled with Erlang/OTP 26)

bild

bild

I run Postgres 15 (postgres.app) and ran these and restarted the server:

ALTER SYSTEM SET wal_level = 'logical';
CREATE PUBLICATION events FOR ALL TABLES;
ALTER TABLE companies REPLICA IDENTITY FULL;
cpursley commented 8 months ago

Thank you for the detailed report @andreaseriksson ~ I noticed something like this as well yesterday - especially after recompiles.

In the latest version I didn't make any changes in the supervision stuff but perhaps this could be the issue: https://github.com/cpursley/walex/blob/master/lib/walex/events.ex#L32

Could you try with the previous version? You won't be able to use the DSL but you can use process behavior (in README - def process(txn) do etc). I won't be able to dig in until this weekend.

andreaseriksson commented 8 months ago

With 2.3.2 it works every time. Restarted server about 15 times 😃

andreaseriksson commented 8 months ago

My guess its the module load order: https://github.com/cpursley/walex/blob/master/lib/walex/events.ex#L37-L40

cpursley commented 8 months ago

@andreaseriksson 3.0.2 release should resolve this issue:

https://github.com/cpursley/walex/blob/master/lib/walex/events.ex#L38

Modules are also now optional in the config if you follow this pattern: MyApp.Events.User, MyApp.Events.ToDo

andreaseriksson commented 8 months ago

✅

cpursley commented 8 months ago

Actually, there's still some issues (around transactions). Working on getting those fixed.