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 pool_size should be equal or greater to 1 #301

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lib/db_connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ defmodule DBConnection do
in `GenServer.start_link/3`)
* `:pool` - Chooses the pool to be started (default: `DBConnection.ConnectionPool`). See
["Connection pools"](#module-connection-pools).
* `:pool_size` - Chooses the size of the pool (default: `1`)
* `:pool_size` - Chooses the size of the pool. Must be greater or equal to 1. (default: `1`)
* `:idle_interval` - Controls the frequency we check for idle connections
in the pool. We then notify each idle connection to ping the database.
In practice, the ping happens within `idle_interval <= ping < 2 * idle_interval`.
Expand Down
3 changes: 3 additions & 0 deletions lib/db_connection/connection_pool/pool.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ defmodule DBConnection.ConnectionPool.Pool do
@impl true
def init({owner, tag, mod, opts}) do
size = Keyword.get(opts, :pool_size, 1)

if size < 1, do: raise(ArgumentError, "pool size must be greater or equal to 1, got #{size}")

children = for id <- 1..size, do: conn(owner, tag, id, mod, opts)
sup_opts = [strategy: :one_for_one] ++ Keyword.take(opts, [:max_restarts, :max_seconds])
Supervisor.init(children, sup_opts)
Expand Down
Loading