electric icon indicating copy to clipboard operation
electric copied to clipboard

Electric incorrectly treats failure to establish unencrypted DB connection an unkown error

Open alco opened this issue 5 months ago • 1 comments

Start Electric with sslmode=disable in DATABASE_URL while connecting to a database that enforces the use of SSL. You'll see the following errors logged:

16:16:57.491 pid=<0.313.0> [debug] Opening lock connection


16:16:57.521 pid=<0.313.0> [error] #PID<0.313.0> (Electric.Postgres.LockConnection) failed to connect to Postgres: ** (Postgrex.Error) FATAL 28000 (invalid_authorization_specification) no pg_hba.conf entry for host "89.105.67.212", user "postgres", database "postgres", no encryption

16:16:57.521 pid=<0.313.0> [error] :gen_statem {:"Electric.ProcessRegistry:single_stack", {Electric.Postgres.LockConnection, nil}} terminating
** (Postgrex.Error) FATAL 28000 (invalid_authorization_specification) no pg_hba.conf entry for host "89.105.67.212", user "postgres", database "postgres", no encryption
    (stdlib 7.0.1) gen_statem.erl:3877: :gen_statem.loop_state_callback_result/11
    (stdlib 7.0.1) proc_lib.erl:333: :proc_lib.init_p_do_apply/3
Process Label: {:lock_connection, "single_stack"}
Queue: [internal: {:connect, :init}]
Postponed: []
State: %Postgrex.SimpleConnection{idle_interval: 5000, protocol: nil, auto_reconnect: false, reconnect_backoff: 500, state: {Electric.Postgres.LockConnection, %Electric.Postgres.LockConnection.State{connection_manager: #PID<0.289.0>, lock_acquired: false, lock_name: "electric_slot_default", backoff: {{:backoff, 1000, 10000, 1000, :normal, :undefined, :undefined}, nil}, stack_id: nil}}}
Callback mode: :handle_event_function, state_enter: false

16:16:57.522 pid=<0.289.0> [error] Electric.DBConnection unknown error: %Postgrex.Error{message: nil, postgres: %{code: :invalid_authorization_specification, line: "533", message: "no pg_hba.conf entry for host \"89.105.67.212\", user \"postgres\", database \"postgres\", no encryption", file: "auth.c", unknown: "FATAL", severity: "FATAL", pg_code: "28000", routine: "ClientAuthentication"}, connection_id: nil, query: nil}

16:16:57.522 pid=<0.289.0> [warning] Database connection in lock_connection mode failed: %Postgrex.Error{message: nil, postgres: %{code: :invalid_authorization_specification, line: "533", message: "no pg_hba.conf entry for host \"89.105.67.212\", user \"postgres\", database \"postgres\", no encryption", file: "auth.c", unknown: "FATAL", severity: "FATAL", pg_code: "28000", routine: "ClientAuthentication"}, connection_id: nil, query: nil} (PG code: 28000, PG routine: ClientAuthentication)
Retrying...

16:16:57.522 pid=<0.289.0> [warning] Reconnecting in 2000ms

Note the log entry

16:16:57.522 pid=<0.289.0> [error] Electric.DBConnection unknown error: %Postgrex.Error{message: nil, postgres: %{code: :invalid_authorization_specification, line: "533", message: "no pg_hba.conf entry for host \"89.105.67.212\", user \"postgres\", database \"postgres\", no encryption", file: "auth.c", unknown: "FATAL", severity: "FATAL", pg_code: "28000", routine: "ClientAuthentication"}, connection_id: nil, query: nil}

This shouldn't be an unknown error since it's expected to happen when the user incorrectly instructs Electric to open an unencrypted connection to the database.

alco avatar Aug 05 '25 14:08 alco

This should be a matter of just parsing it like we do the rest right?

msfstef avatar Sep 07 '25 15:09 msfstef