Skip to content

Commit 775b85a

Browse files
committed
:timeout option is now considered when receiving the response
1 parent 832c0f9 commit 775b85a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/mongo/mongo_db_connection.ex

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,16 +256,18 @@ defmodule Mongo.MongoDBConnection do
256256
end
257257
defp execute_action(:command, [cmd], opts, %{wire_version: version} = state) when version >= 6 do
258258

259-
cmd = cmd ++ ["$db": opts[:database] || state.database,
260-
"$readPreference": [mode: update_read_preferences(opts[:slave_ok])]]
259+
cmd = cmd ++ ["$db": opts[:database] || state.database, "$readPreference": [mode: update_read_preferences(opts[:slave_ok])]]
261260

262261
# MongoDB 3.6 only allows certain command arguments to be provided this way. These are:
263262
op = case pulling_out?(cmd, :documents) || pulling_out?(cmd, :updates) || pulling_out?(cmd, :deletes) do
264263
nil -> op_msg(flags: 0, sections: [section(payload_type: 0, payload: payload(doc: cmd))])
265264
key -> pulling_out(cmd, key)
266265
end
267266

268-
with {:ok, doc} <- Utils.post_request(op, state.request_id, state),
267+
# overwrite temporary timeout by timeout option
268+
timeout = Keyword.get(opts, :timeout, state.timeout)
269+
270+
with {:ok, doc} <- Utils.post_request(op, state.request_id, %{state | timeout: timeout}),
269271
state = %{state | request_id: state.request_id + 1} do
270272
{:ok, doc, state}
271273
end
@@ -274,8 +276,8 @@ defmodule Mongo.MongoDBConnection do
274276

275277
flags = Keyword.take(opts, @find_one_flags)
276278
op = op_query(coll: Utils.namespace("$cmd", state, opts[:database]), query: cmd, select: "", num_skip: 0, num_return: 1, flags: flags(flags))
277-
278-
with {:ok, doc} <- Utils.post_request(op, state.request_id, state),
279+
timeout = Keyword.get(opts, :timeout, state.timeout)
280+
with {:ok, doc} <- Utils.post_request(op, state.request_id, %{state | timeout: timeout}),
279281
state = %{state | request_id: state.request_id + 1} do
280282
{:ok, doc, state}
281283
end

0 commit comments

Comments
 (0)