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

supabase / realtime / 95e65e20dbf37d801611cc277ce3ef3c47de5f02-PR-1555

02 Oct 2025 06:39PM UTC coverage: 85.17% (-0.03%) from 85.202%
95e65e20dbf37d801611cc277ce3ef3c47de5f02-PR-1555

Pull #1555

github

filipecabaco
ignore presence test for now
Pull Request #1555: fix: move connect rate limit to socket

9 of 15 new or added lines in 2 files covered. (60.0%)

2102 of 2468 relevant lines covered (85.17%)

2760.3 hits per line

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

80.0
/lib/realtime_web/channels/tenant_rate_limiters.ex
1
defmodule RealtimeWeb.Channels.TenantRateLimiters do
2
  @moduledoc """
3
  Rate limiters for tenants.
4
  """
5
  require Logger
6
  alias Realtime.UsersCounter
7
  alias Realtime.GenCounter
8
  alias Realtime.Tenants
9
  alias Realtime.RateCounter
10
  alias Realtime.Api.Tenant
11

12
  @spec check_tenant(any()) :: :ok | {:error, :too_many_connections | :too_many_joins}
13
  def check_tenant(tenant) do
14
    with :ok <- max_concurrent_users_check(tenant) do
117✔
15
      max_joins_per_second_check(tenant)
117✔
16
    end
17
  end
18

19
  def max_concurrent_users_check(%Tenant{max_concurrent_users: max_conn_users, external_id: external_id}) do
20
    total_conn_users = UsersCounter.tenant_users(external_id)
117✔
21

22
    if total_conn_users < max_conn_users,
117✔
23
      do: :ok,
24
      else: {:error, :too_many_connections}
25
  end
26

27
  def max_joins_per_second_check(%Tenant{max_joins_per_second: max_joins_per_second} = tenant) do
28
    rate_args = Tenants.joins_per_second_rate(tenant.external_id, max_joins_per_second)
117✔
29

30
    RateCounter.new(rate_args)
117✔
31

32
    case RateCounter.get(rate_args) do
117✔
33
      {:ok, %{limit: %{triggered: false}}} ->
34
        GenCounter.add(rate_args.id)
117✔
35
        :ok
36

NEW
37
      {:ok, %{limit: %{triggered: true}}} ->
×
38
        {:error, :too_many_joins}
39

40
      error ->
NEW
41
        Logger.error("UnknownErrorOnCounter: #{inspect(error)}")
×
42
        {:error, error}
43
    end
44
  end
45
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

© 2025 Coveralls, Inc