lib/mongo/server_selector/base.rb in mongo-2.15.0.alpha vs lib/mongo/server_selector/base.rb in mongo-2.15.0
- old
+ new
@@ -1,5 +1,8 @@
+# frozen_string_literal: true
+# encoding: utf-8
+
# Copyright (C) 2020 MongoDB Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
@@ -179,11 +182,11 @@
msg = "Failing server selection due to zero timeout. " +
" Requested #{name} in cluster: #{cluster.summary}"
raise Error::NoServerAvailable.new(self, cluster, msg)
end
- deadline = Time.now + server_selection_timeout
+ deadline = Utils.monotonic_time + server_selection_timeout
if session && session.pinned_server
if Mongo::Lint.enabled?
unless cluster.sharded?
raise Error::LintError, "Session has a pinned server in a non-sharded topology: #{topology}"
@@ -197,11 +200,11 @@
if server = session.pinned_server
# Here we assume that a mongos stays in the topology indefinitely.
# This will no longer be the case once SRV polling is implemented.
unless server.mongos?
- while (time_remaining = deadline - Time.now) > 0
+ while (time_remaining = deadline - Utils.monotonic_time) > 0
wait_for_server_selection(cluster, time_remaining)
end
unless server.mongos?
msg = "The session being used is pinned to the server which is not a mongos: #{server.summary} " +
@@ -250,10 +253,10 @@
return server
end
cluster.scan!(false)
- time_remaining = deadline - Time.now
+ time_remaining = deadline - Utils.monotonic_time
if time_remaining > 0
wait_for_server_selection(cluster, time_remaining)
# If we wait for server selection, perform another round of
# attempting to locate a suitable server. Otherwise server selection