Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: always monitor the manager #498

Merged
merged 6 commits into from
Nov 27, 2024
Merged
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
12 changes: 9 additions & 3 deletions lib/supavisor/client_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@

key = {:secrets, tenant_or_alias, user}

case auth_secrets(info, user, key, :timer.hours(24)) do

Check warning on line 278 in lib/supavisor/client_handler.ex

View workflow job for this annotation

GitHub Actions / Code style

Function body is nested too deep (max depth is 2, was 3).
{:ok, auth_secrets} ->
Logger.debug("ClientHandler: Authentication method: #{inspect(auth_secrets)}")

Expand Down Expand Up @@ -334,7 +334,7 @@
Cachex.get(Supavisor.Cache, key) == {:ok, nil} do
case auth_secrets(info, data.user, key, 15_000) do
{:ok, {method2, secrets2}} = value ->
if method != method2 or Map.delete(secrets.(), :client_key) != secrets2.() do

Check warning on line 337 in lib/supavisor/client_handler.ex

View workflow job for this annotation

GitHub Actions / Code style

Function body is nested too deep (max depth is 2, was 4).
Logger.warning("ClientHandler: Update secrets and terminate pool")

Cachex.update(
Expand Down Expand Up @@ -395,10 +395,10 @@
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 == [],
Expand All @@ -424,6 +424,9 @@
: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,
Expand All @@ -434,6 +437,9 @@
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 ->
Expand Down Expand Up @@ -623,7 +629,7 @@
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)}"
)
Expand Down
Loading