Skip to content

Commit

Permalink
Rescue ConnectionError in peer leadership check
Browse files Browse the repository at this point in the history
Previously, only `Postgrex.Error` exceptions were rescued and other
standard connection errors were ignored, crashing the Peer. Because
leadership is checked immediately after the Peer initializes, any
connection issues would trigger a crash loop that could bring down the
rest of the supervision tree.

Closes #1026
  • Loading branch information
sorentwo committed Apr 6, 2024
1 parent 181780f commit 5743f21
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/oban/peers/postgres.ex
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ defmodule Oban.Peers.Postgres do

{:noreply, schedule_election(state)}
rescue
error in [Postgrex.Error] ->
if error.postgres.code == :undefined_table do
Logger.warning("""
error in [DBConnection.ConnectionError, Postgrex.Error] ->
if match?(%{postgres: %{code: :undefined_table}}, error) do
Logger.error("""
The `oban_peers` table is undefined and leadership is disabled.
Run migrations up to v11 to restore peer leadership. In the meantime, distributed plugins
(e.g. Cron, Pruner, Stager) will not run on any nodes.
(e.g. Cron, Pruner) will not run on any nodes.
""")
end

Expand Down

0 comments on commit 5743f21

Please sign in to comment.