Skip to content

Commit

Permalink
Shield pooled connections from exceptions in user functions
Browse files Browse the repository at this point in the history
  • Loading branch information
alco committed Oct 2, 2023
1 parent ee9adcb commit 83f9876
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions components/electric/lib/electric/postgres/connection_pool.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,21 @@ defmodule Electric.Postgres.ConnectionPool do
NimblePool.checkout!(
pool,
:checkout,
fn _pool, conn ->
{fun.(conn), :ok}
end,
fn _pool, conn -> {execute_fun_with_conn(fun, conn), :ok} end,
@pool_timeout
)
end

defp execute_fun_with_conn(fun, conn) do
try do
fun.(conn)
rescue
e ->
Logger.error(Exception.format(:error, e, __STACKTRACE__))
{:error, e}
end
end

@spec name(Connectors.origin()) :: Electric.reg_name()
def name(origin) when is_binary(origin) do
Electric.name(__MODULE__, origin)
Expand Down

0 comments on commit 83f9876

Please sign in to comment.