martasd

martasd

DBConnection logging exception when interacting with Event Store

Hi,

I am seeing the following exception in Phoenix server debug log when I execute a mutation to register a new user in my application:

[debug] Core.ProcessManagers.Registrator has been stopped by event 15 ("fefce8e5-aabc-4cd6-834c-44cae8ce6b4d"@5)
[error] an exception was raised logging %DBConnection.LogEntry{call: :prepare_execute, connection_time: 2358000, decode_time: 3000, idle_time: 12662000, 
params: ["\"Core.ProcessManagers.Registrator\"-\"fefce8e5-aabc-4cd6-834c-44cae8ce6b4d\""], pool_time: 1329000, 
query: %Postgrex.Query{cache: :reference, columns: nil, name: "", param_formats: nil, param_oids: nil, param_types: nil, ref: nil, result_formats: nil, result_oids: nil, result_types: nil, 
statement: ["DELETE FROM ", "public", ".snapshots\nWHERE source_uuid = $1;\n"], types: nil}, 
result: {:ok, %Postgrex.Query{cache: :reference, columns: nil, name: "", param_formats: [:binary], param_oids: [25], param_types: [Postgrex.Extensions.Raw], ref: #Reference<0.796564844.2413297668.48472>, result_formats: [], result_oids: nil, result_types: nil, 
statement: ["DELETE FROM ", "public", ".snapshots\nWHERE source_uuid = $1;\n"], types: {Postgrex.DefaultTypes, #Reference<0.796564844.2413428738.50179>}}, %Postgrex.Result{columns: nil, command: :delete, connection_id: 460, messages: [], num_rows: 1, rows: nil}}}: 
** (BadFunctionError) expected a function, got: false
    (db_connection 2.4.1) lib/db_connection.ex:1501: DBConnection.log/2
    (db_connection 2.4.1) lib/db_connection.ex:1479: DBConnection.log/5
    (postgrex 0.15.13) lib/postgrex.ex:313: Postgrex.query_prepare_execute/4
    (eventstore 1.3.2) lib/event_store/storage/snapshot.ex:63: EventStore.Storage.Snapshot.delete_snapshot/3
    (commanded 1.3.1) lib/commanded/process_managers/process_manager_instance.ex:114: Commanded.ProcessManagers.ProcessManagerInstance.handle_call/3
    (stdlib 3.17) gen_server.erl:721: :gen_server.try_handle_call/4
    (stdlib 3.17) gen_server.erl:750: :gen_server.handle_msg/6
    (stdlib 3.17) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

[debug] Core.ProcessManagers.Registrator confirming receipt of event: 15

I actually see DBConnection.LogEntry in each interaction with the event store always receiving the same BadFunctionError. I’ve already gone through the suggestions in this thread: Telemetry Logging Error, but have not made any progress. Any ideas what is going on here?

Environment

  • Elixir 1.12.3
  • Ecto 3.7.1
  • Postgres 13.5

Marked As Solved

martasd

martasd

Thanks for the pointers. It seems that I’ve found the source of the error. I have the following configuration:

postgres_config = [
  adapter: Ecto.Adapters.Postgres,
  username: System.get_env("POSTGRES_USER"),
  password: System.get_env("POSTGRES_PASSWORD"),
  hostname: System.get_env("POSTGRES_HOST"),
  port: "5432",
  show_sensitive_data_on_connection_error: true,
  log: false
]

When I remove log: false, the error disappears. Both the option and its value false are valid according to the docs, however: Ecto.Repo — Ecto v3.14.0. This is suggesting that the problem lies somewhere between Postgrex and DB Connection.

Also Liked

al2o3cr

al2o3cr

The code that’s raising BadFunctionError in DBConnection.log/2 is handling the log option passed in opts to most functions in DBConnection. This accepts either nil, an arity 1 function, or an MFA tuple - in particular, it DOES NOT accept false, which would cause exactly the error you’re seeing.

https://github.com/elixir-ecto/db_connection/blob/46888ada567401d1270f855a3dd04bfca545f94f/lib/db_connection.ex#L503-L505

al2o3cr

al2o3cr

eventstore doesn’t use Ecto, it talks directly to the Postgrex driver.

Ecto’s options in log: (like :debug or false) are transformed into what the adapter expects in Ecto.Adapters.SQL.with_log:

https://github.com/elixir-ecto/ecto_sql/blob/master/lib/ecto/adapters/sql.ex#L1050-L1052

The configuration you pass to eventstore needs to match the expectations for log cited previously

Last Post!

al2o3cr

al2o3cr

eventstore doesn’t use Ecto, it talks directly to the Postgrex driver.

Ecto’s options in log: (like :debug or false) are transformed into what the adapter expects in Ecto.Adapters.SQL.with_log:

https://github.com/elixir-ecto/ecto_sql/blob/master/lib/ecto/adapters/sql.ex#L1050-L1052

The configuration you pass to eventstore needs to match the expectations for log cited previously

Where Next?

Popular in Questions Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54006 488
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement