Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions integration_test/ownership/owner_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,21 @@ defmodule OwnerTest do
{:connect, _}
] = A.record(agent)
end

test "ignores a late deadline timer for a previous holder" do
stack = [{:ok, :state}] ++ List.duplicate({:idle, :state}, 2)
{:ok, agent} = A.start_link(stack)

opts = [agent: agent, ownership_mode: :manual]
{:ok, pool} = P.start_link(opts)

:ok = Ownership.ownership_checkout(pool, [])
{:owner, _ref, proxy} = Map.fetch!(:sys.get_state(pool).checkouts, self())
monitor_ref = Process.monitor(proxy)

send(proxy, {:timeout, make_ref(), {make_ref(), make_ref(), self(), 15_000}})

assert %{source: {:proxy, ^proxy}} = GenServer.call(proxy, :get_connection_metrics)
refute_receive {:DOWN, ^monitor_ref, :process, ^proxy, _reason}
end
end
6 changes: 6 additions & 0 deletions lib/db_connection/ownership/proxy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ defmodule DBConnection.Ownership.Proxy do
end
end

# Deadline timers are cancelled asynchronously, so their messages may arrive
# after the holder has been transferred or replaced.
def handle_info({:timeout, _deadline, {_ref, _holder, _pid, _len}}, state) do
{:noreply, state}
end

def handle_info(
{:timeout, timer, {__MODULE__, pid, timeout}},
%{ownership_timer: timer} = state
Expand Down
Loading