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

chore: calculate concurrent users only for successfully connected ses… #535

Merged
merged 2 commits into from
Jan 8, 2025
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: 3 additions & 9 deletions lib/supavisor/client_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,6 @@
local: data.local
)

Registry.register(@clients_registry, id, [])

{:ok, addr} = HandlerHelpers.addr_from_sock(sock)

cond do
Expand Down Expand Up @@ -336,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 @@ -402,6 +400,8 @@
db_pid = db_checkout(:both, :on_connect, data)
data = %{data | manager: manager_ref, db_pid: db_pid, idle_timeout: opts.idle_timeout}

Registry.register(@clients_registry, data.id, [])

next =
if opts.ps == [],
do: {:timeout, 10_000, :wait_ps},
Expand Down Expand Up @@ -437,7 +437,7 @@
})

Logger.metadata(proxy: true)
set_proxy_registry(data.id)
Registry.register(@proxy_clients_registry, data.id, [])

{:keep_state, %{data | auth: auth}, {:next_event, :internal, :connect_db}}

Expand Down Expand Up @@ -574,7 +574,7 @@
db_pid = handle_db_pid(data.mode, data.pool, data.db_pid)

{_, stats} =
if not data.local,

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

View workflow job for this annotation

GitHub Actions / Code style

Avoid negated conditions in if-else blocks.
do: Telem.network_usage(:client, data.sock, data.id, data.stats),
else: {nil, data.stats}

Expand Down Expand Up @@ -1158,10 +1158,4 @@
HandlerHelpers.activate(data.sock)
0
end

@spec set_proxy_registry(Supavisor.id()) :: {:ok, pid()} | {:error, term()}
defp set_proxy_registry(id) do
Registry.unregister(@clients_registry, id)
Registry.register(@proxy_clients_registry, id, [])
end
end
Loading