diff --git a/lib/supavisor/client_handler.ex b/lib/supavisor/client_handler.ex index 35244a51..b1e06c61 100644 --- a/lib/supavisor/client_handler.ex +++ b/lib/supavisor/client_handler.ex @@ -395,10 +395,10 @@ defmodule Supavisor.ClientHandler do else: true ), {:ok, opts} <- Supavisor.subscribe(sup, data.id) do - Process.monitor(opts.workers.manager) + manager_ref = Process.monitor(opts.workers.manager) data = Map.merge(data, opts.workers) db_pid = db_checkout(:both, :on_connect, data) - data = %{data | db_pid: db_pid, idle_timeout: opts.idle_timeout} + data = %{data | manager: manager_ref, db_pid: db_pid, idle_timeout: opts.idle_timeout} next = if opts.ps == [], @@ -424,6 +424,9 @@ defmodule Supavisor.ClientHandler do :proxy -> case Supavisor.get_pool_ranch(data.id) do {:ok, %{port: port, host: host}} -> + # Not sure if manager is alive yet + # manager_ref = Process.monitor(opts.workers.manager) + auth = Map.merge(data.auth, %{ port: port, @@ -434,6 +437,9 @@ defmodule Supavisor.ClientHandler do upstream_verify: nil }) + # {:keep_state, %{data | auth: auth, manager: manager_ref}, + # {:next_event, :internal, :connect_db}} + {:keep_state, %{data | auth: auth}, {:next_event, :internal, :connect_db}} other -> @@ -623,7 +629,7 @@ defmodule Supavisor.ClientHandler do end # pool's manager went down - def handle_event(:info, {:DOWN, _, _, _, reason}, state, data) do + def handle_event(:info, {:DOWN, ref, _, _, reason}, state, %{manager: ref} = data) do Logger.error( "ClientHandler: Manager #{inspect(data.manager)} went down #{inspect(reason)} state #{inspect(state)}" )