Skip to content

Commit 0372e56

Browse files
authored
Merge pull request #98 from zookzook/PR/add-timeout-option-for-checkout
#97: added new option :checkout_timeout
2 parents 6d2aa33 + 1d468ba commit 0372e56

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

lib/mongo.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ defmodule Mongo do
1010
* `:timeout` - The maximum time that the caller is allowed the to hold the
1111
connection’s state (ignored when using a run/transaction connection,
1212
default: `15_000`)
13+
* `:checkout_timeout` - The maximum time for checking out a new session and connection (default: `60_000`).
14+
When the connection pool exhausted then the function call times out after :checkout_timeout.
1315
* `:pool` - The pooling behaviour module to use, this option is required
1416
unless the default `DBConnection.Connection` pool is used
1517
* `:pool_timeout` - The maximum time to wait for a reply when making a

lib/mongo/topology.ex

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ defmodule Mongo.Topology do
1818
# https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#heartbeatfrequencyms-defaults-to-10-seconds-or-60-seconds
1919
@heartbeat_frequency_ms 10_000
2020

21+
@default_checkout_timeout 60_000
22+
2123
@spec start_link(Keyword.t, Keyword.t) ::
2224
{:ok, pid} |
2325
{:error, reason :: atom}
@@ -51,8 +53,9 @@ defmodule Mongo.Topology do
5153
GenServer.call(pid, :topology)
5254
end
5355

54-
def select_server(pid, type, opts \\ []) do
55-
GenServer.call(pid, {:select_server, type, opts})
56+
def select_server(pid, type, opts \\ []) do#97
57+
timeout = Keyword.get(opts, :checkout_timeout, @default_checkout_timeout)
58+
GenServer.call(pid, {:select_server, type, opts}, timeout)
5659
end
5760

5861
def limits(pid) do
@@ -63,11 +66,9 @@ defmodule Mongo.Topology do
6366
GenServer.call(pid, :wire_version)
6467
end
6568

66-
@doc """
67-
68-
"""
6969
def checkout_session(pid, cmd_type, type, opts \\ []) do
70-
GenServer.call(pid, {:checkout_session, cmd_type, type, opts})
70+
timeout = Keyword.get(opts, :checkout_timeout, @default_checkout_timeout)
71+
GenServer.call(pid, {:checkout_session, cmd_type, type, opts}, timeout)
7172
end
7273

7374
def checkin_session(pid, server_session) do

0 commit comments

Comments
 (0)