Skip to content
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
10 changes: 5 additions & 5 deletions lib/db_connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -440,12 +440,12 @@ defmodule DBConnection do

* `:max_lifetime` - The number of ms the connection is allowed to live.
It is a range so you can jitter/spread disconnections over some time period.
For example, to have a max lifetime between 8 and 9 minutes, you ca set it
For example, to have a max lifetime between 8 and 9 minutes, you can set it
to `480_000..540_000`. Because the timer is started *after* the connection
to the database is established and on checkout, the connection may live for
slightly longer. If the connection is idle, the worst case wait is of
`540_000 + idle_limit`. If the connection is in use, it may last as long as
the connection is checked out over the max period. Default is `nil`.
to the database is established, the connection may live for slightly longer.
If the connection is idle, the worst case wait is of
`540_000 + 2 * idle_interval`. If the connection is in use, it may last as
long as the connection is checked out over the max period. Default is `nil`.

* `:name` - A name to register the started process (see the `:name` option
in `GenServer.start_link/3`)
Expand Down
4 changes: 2 additions & 2 deletions lib/db_connection/connection_pool.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ defmodule DBConnection.ConnectionPool do

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

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

:error ->
nil
Expand Down
4 changes: 2 additions & 2 deletions lib/db_connection/holder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,10 @@ defmodule DBConnection.Holder do
defp max_lifetime_reason(nil, _ts, _holder), do: nil

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

# First check if passed start then check if also the interval
if ellapsed > start and ellapsed > hash_holder(holder, interval_ms) + start do
if elapsed > start and elapsed > hash_holder(holder, interval_ms) + start do
"max_lifetime exceeded"
end
end
Expand Down
Loading