Skip to content

Commit 4d7d6d8

Browse files
authored
Fix max_lifetime docstring inaccuracies, validation, and typos (#345)
1 parent eb08c76 commit 4d7d6d8

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

lib/db_connection.ex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -440,12 +440,12 @@ defmodule DBConnection do
440440
441441
* `:max_lifetime` - The number of ms the connection is allowed to live.
442442
It is a range so you can jitter/spread disconnections over some time period.
443-
For example, to have a max lifetime between 8 and 9 minutes, you ca set it
443+
For example, to have a max lifetime between 8 and 9 minutes, you can set it
444444
to `480_000..540_000`. Because the timer is started *after* the connection
445-
to the database is established and on checkout, the connection may live for
446-
slightly longer. If the connection is idle, the worst case wait is of
447-
`540_000 + idle_limit`. If the connection is in use, it may last as long as
448-
the connection is checked out over the max period. Default is `nil`.
445+
to the database is established, the connection may live for slightly longer.
446+
If the connection is idle, the worst case wait is of
447+
`540_000 + 2 * idle_interval`. If the connection is in use, it may last as
448+
long as the connection is checked out over the max period. Default is `nil`.
449449
450450
* `:name` - A name to register the started process (see the `:name` option
451451
in `GenServer.start_link/3`)

lib/db_connection/connection_pool.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ defmodule DBConnection.ConnectionPool do
5757

5858
max_lifetime =
5959
case Keyword.fetch(opts, :max_lifetime) do
60-
{:ok, %Range{first: first, last: last, step: 1}} ->
60+
{:ok, %Range{first: first, last: last, step: 1}} when first >= 0 and last >= first ->
6161
{System.convert_time_unit(first, :millisecond, :native), last - first}
6262

6363
{:ok, invalid} ->
6464
raise ArgumentError,
65-
"invalid value for :max_lifetime, expected a step-1 range, got: #{inspect(invalid)}"
65+
"invalid value for :max_lifetime, expected a non-negative step-1 range, got: #{inspect(invalid)}"
6666

6767
:error ->
6868
nil

lib/db_connection/holder.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,10 @@ defmodule DBConnection.Holder do
262262
defp max_lifetime_reason(nil, _ts, _holder), do: nil
263263

264264
defp max_lifetime_reason({start, interval_ms}, ts, holder) do
265-
ellapsed = System.monotonic_time() - ts
265+
elapsed = System.monotonic_time() - ts
266266

267267
# First check if passed start then check if also the interval
268-
if ellapsed > start and ellapsed > hash_holder(holder, interval_ms) + start do
268+
if elapsed > start and elapsed > hash_holder(holder, interval_ms) + start do
269269
"max_lifetime exceeded"
270270
end
271271
end

0 commit comments

Comments
 (0)