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: Allow Overriding of max_channels_per_client via Environment Variable #866

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

barrownicholas
Copy link

What kind of change does this PR introduce?

Bug fix: allows overriding the default of 100 for max_channels_per_client on a realtime tenant.

What is the current behavior?

The default is locked at 100 without any ready way to override it.

What is the new behavior?

Allows a user to specify MAX_CHANNELS_PER_CLIENT in the runtime environment to override this value.

Additional context

Fixes #843

Copy link

vercel bot commented May 3, 2024

@barrownicholas is attempting to deploy a commit to the Supabase Team on Vercel.

A member of the Team first needs to authorize it.

@barrownicholas
Copy link
Author

@filipecabaco when you have time could you take a peak at this? You've been a huge help in the past, sorry to bother, you're just the best point-of-contact I have!!

@barrownicholas barrownicholas changed the title Allow Overriding of max_channels_per_client via Environment Variable fix: Allow Overriding of max_channels_per_client via Environment Variable May 3, 2024
@@ -388,7 +388,7 @@ defmodule RealtimeWeb.RealtimeChannel do
def limit_channels(%{assigns: %{tenant: tenant, limits: limits}, transport_pid: pid}) do
key = Tenants.channels_per_client_key(tenant)

if Registry.count_match(Realtime.Registry, key, pid) > limits.max_channels_per_client do
if Registry.count_match(Realtime.Registry, key, pid) > String.to_integer(System.get_env("MAX_CHANNELS_PER_CLIENT") || Integer.to_string(limits.max_channels_per_client)) do
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this first checks (for existing tenants) if MAX_CHANNELS_PER_CLIENT and uses that value (or defaults back to the limit existing on the tenant) for backwards compatibility. Both are treated as strings to allow comparison, before finally being converted back to an integer for use/processing.

@@ -18,6 +18,7 @@ Repo.transaction(fn ->
"external_id" => tenant_name,
"jwt_secret" =>
System.get_env("API_JWT_SECRET", "super-secret-jwt-token-with-at-least-32-characters-long"),
"max_channels_per_client" => String.to_integer(System.get_env("MAX_CHANNELS_PER_CLIENT") || "100"),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

always use the new value on new clients, default back to system default of 100

@barrownicholas
Copy link
Author

Also, can confirm that this built successfully in Docker on my local machine

@filipecabaco
Copy link
Contributor

👋 will check today sorry for the delay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

too_many_channels error: "{:error, :too_many_channels}"
2 participants