Skip to content

Commit

Permalink
fix(connection): Rollback on disconnect
Browse files Browse the repository at this point in the history
If the auto_commit mode has been turned off we now send a rollback message to each process before a disconnect so ODBC can gracefully end the connection.
  • Loading branch information
PM-Pepsico committed Jan 12, 2023
1 parent ffcc04e commit 0b93424
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/snowflex/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,17 @@ defmodule Snowflex.Connection do
end

@impl DBConnection
def disconnect(_err, %{pid: pid}), do: Client.disconnect(pid)
def disconnect(_err, %{pid: pid, conn_opts: conn_opts}) do
auto_commit =
case Keyword.fetch(conn_opts, :auto_commit) do
{:ok, mode} -> mode
:error -> :on
end

if auto_commit == :off, do: Client.commit(pid, :rollback)

Client.disconnect(pid)
end

@impl DBConnection
def checkout(state), do: {:ok, state}
Expand Down

0 comments on commit 0b93424

Please sign in to comment.