Skip to content

Commit

Permalink
fix: max clients in session mode error (#473)
Browse files Browse the repository at this point in the history
* fix: update max clients error in session mode
  • Loading branch information
chasers authored Nov 8, 2024
1 parent 3222cd9 commit a79f2eb
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 48 deletions.
9 changes: 9 additions & 0 deletions docs/monitoring/logs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Supavisor will emit various logs during operation.

Use these error codes to debug a running Supavisor cluster.

## Error Codes

| Code | Description |
| ----------------------- | -------------------------------------------------------------------- |
| MaxClientsInSessionMode | When in Session mode client connections are limited by the pool_size |
2 changes: 1 addition & 1 deletion lib/supavisor/client_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ defmodule Supavisor.ClientHandler do
msg =
case data.mode do
:session ->
"Max client connections reached"
"MaxClientsInSessionMode: max clients reached - in Session mode max clients are limited to pool_size"

:transaction ->
"Unable to check out process from the pool due to timeout"
Expand Down
2 changes: 1 addition & 1 deletion lib/supavisor/manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ defmodule Supavisor.Manager do

# don't limit if max_clients is null
{reply, new_state} =
if :ets.info(state.tid, :size) < state.max_clients do
if :ets.info(state.tid, :size) < state.max_clients or Supavisor.mode(state.id) == :session do
:ets.insert(state.tid, {Process.monitor(pid), pid, now()})

case state.parameter_status do
Expand Down
89 changes: 45 additions & 44 deletions mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,52 @@ repo_name: supabase/supavisor
repo_url: https://github.com/supabase/supavisor

nav:
- Welcome: 'index.md'
- FAQ: 'faq.md'
- Development:
- Installation: 'development/installation.md'
- Setup: 'development/setup.md'
- Docs: 'development/docs.md'
- Deployment:
- Deploy with Fly.io: 'deployment/fly.md'
- Connecting:
- Overview: 'connecting/overview.md'
- Authentication: 'connecting/authentication.md'
- Configuration:
- Tenants: 'configuration/tenants.md'
- Users: 'configuration/users.md'
- Pool Modes: 'configuration/pool_modes.md'
- Migrating:
- from PgBouncer: 'migrating/pgbouncer.md'
- Monitoring:
- Metrics: 'monitoring/metrics.md'
- ORMs:
- Prisma: 'orms/prisma.md'
- Welcome: "index.md"
- FAQ: "faq.md"
- Development:
- Installation: "development/installation.md"
- Setup: "development/setup.md"
- Docs: "development/docs.md"
- Deployment:
- Deploy with Fly.io: "deployment/fly.md"
- Connecting:
- Overview: "connecting/overview.md"
- Authentication: "connecting/authentication.md"
- Configuration:
- Tenants: "configuration/tenants.md"
- Users: "configuration/users.md"
- Pool Modes: "configuration/pool_modes.md"
- Migrating:
- from PgBouncer: "migrating/pgbouncer.md"
- Monitoring:
- Metrics: "monitoring/metrics.md"
- Logs: "monitoring/logs.md"
- ORMs:
- Prisma: "orms/prisma.md"

theme:
name: 'material'
favicon: 'images/favicon.ico'
logo: 'images/favicon.ico'
homepage: https://supabase.github.io/supavisor
features:
- navigation.expand
palette:
primary: black
accent: light green
name: "material"
favicon: "images/favicon.ico"
logo: "images/favicon.ico"
homepage: https://supabase.github.io/supavisor
features:
- navigation.expand
palette:
primary: black
accent: light green

markdown_extensions:
- pymdownx.highlight:
linenums: true
guess_lang: false
use_pygments: true
pygments_style: default
- pymdownx.superfences
- pymdownx.tabbed:
alternate_style: true
- pymdownx.snippets
- pymdownx.tasklist
- admonition
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg
- pymdownx.highlight:
linenums: true
guess_lang: false
use_pygments: true
pygments_style: default
- pymdownx.superfences
- pymdownx.tabbed:
alternate_style: true
- pymdownx.snippets
- pymdownx.tasklist
- admonition
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg
2 changes: 1 addition & 1 deletion priv/repo/seeds_after_migration.exs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ end
"db_user_alias" => "max_clients",
"db_user" => db_conf[:username],
"db_password" => db_conf[:password],
"pool_size" => 2,
"pool_size" => 1,
"max_clients" => -1,
"mode_type" => "transaction",
"pool_checkout_timeout" => 500
Expand Down
10 changes: 9 additions & 1 deletion test/integration/proxy_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,24 @@ defmodule Supavisor.Integration.ProxyTest do
port: port
)

{:ok, pid1} = single_connection(connection_opts)
{:ok, pid2} = single_connection(connection_opts)

:timer.sleep(1000)

assert {:error,
%Postgrex.Error{
postgres: %{
code: :internal_error,
message: "Max client connections reached",
message:
"MaxClientsInSessionMode: max clients reached - in Session mode max clients are limited to pool_size",
unknown: "FATAL",
severity: "FATAL",
pg_code: "XX000"
}
}} = single_connection(connection_opts)

for pid <- [pid1, pid2], do: :gen_statem.stop(pid)
end

test "http to proxy server returns 200 OK" do
Expand Down

0 comments on commit a79f2eb

Please sign in to comment.