• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / supavisor / 22685842482

04 Mar 2026 07:34PM UTC coverage: 78.255% (+3.1%) from 75.154%
22685842482

Pull #865

github

web-flow
Merge 0c00c3cdf into cdc0a6724
Pull Request #865: fix: use a pool for starting proxy connections

25 of 58 new or added lines in 6 files covered. (43.1%)

11 existing lines in 3 files now uncovered.

2404 of 3072 relevant lines covered (78.26%)

4027.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lib/supavisor/client_handler/proxy_supervisor.ex
1
defmodule Supavisor.ClientHandler.ProxySupervisor do
2
  @moduledoc """
3
  Wrapping supervisor for proxy connections of a single tenant.
4

5
  Children:
6
    1. A DynamicSupervisor (`:max_children` enforces the connection limit),
7
       registered in `Supavisor.Registry.Tenants` under `{:proxy_dyn_sup, id}`.
8
    2. A watchdog (significant child) that terminates when the DynamicSupervisor
9
       is empty, triggering `auto_shutdown: :any_significant` on this supervisor.
10
  """
11

12
  use Supervisor
13

14
  alias Supavisor.ClientHandler.ProxySupervisorWatchdog
15

16
  @registry Supavisor.Registry.Tenants
17

18
  def start_link(opts) do
NEW
19
    Supervisor.start_link(__MODULE__, opts)
×
20
  end
21

22
  def child_spec(opts) do
NEW
23
    %{
×
24
      id: __MODULE__,
25
      start: {__MODULE__, :start_link, [opts]},
26
      type: :supervisor,
27
      restart: :temporary
28
    }
29
  end
30

31
  @doc """
32
  Starts a child under the proxy DynamicSupervisor.
33

34
  Returns `{:ok, pid}` on success, `{:error, :max_children}` if the
35
  connection limit has been reached, or `{:error, term}` on other failures.
36
  """
37
  def start_connection(id, child_spec) do
NEW
38
    [{dyn_sup, _}] = Registry.lookup(@registry, {:proxy_dyn_sup, id})
×
NEW
39
    DynamicSupervisor.start_child(dyn_sup, child_spec)
×
40
  end
41

42
  @doc """
43
  Returns the watchdog pid for the given proxy supervisor.
44
  """
45
  def get_watchdog(proxy_sup) do
NEW
46
    {_, pid, _, _} =
×
47
      proxy_sup
48
      |> Supervisor.which_children()
49
      |> List.keyfind(:watchdog, 0)
50

NEW
51
    pid
×
52
  end
53

54
  @impl true
55
  def init(opts) do
NEW
56
    id = Keyword.fetch!(opts, :id)
×
NEW
57
    max_clients = Keyword.fetch!(opts, :max_clients)
×
NEW
58
    watchdog_opts = Keyword.get(opts, :watchdog_opts, [])
×
59

NEW
60
    children = [
×
61
      %{
62
        id: :connections,
63
        start:
64
          {DynamicSupervisor, :start_link,
65
           [
66
             [
67
               strategy: :one_for_one,
68
               max_children: max_clients,
69
               name: {:via, Registry, {@registry, {:proxy_dyn_sup, id}}}
70
             ]
71
           ]},
72
        type: :supervisor
73
      },
74
      %{
75
        id: :watchdog,
76
        start: {ProxySupervisorWatchdog, :start_link, [id, watchdog_opts]},
77
        significant: true,
78
        restart: :temporary
79
      }
80
    ]
81

NEW
82
    Supervisor.init(children, strategy: :one_for_one, auto_shutdown: :any_significant)
×
83
  end
84
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc