diff --git a/lib/mongo/server/round_trip_time_calculator.rb b/lib/mongo/server/round_trip_time_calculator.rb index 99ee7eb60e..468ca02359 100644 --- a/lib/mongo/server/round_trip_time_calculator.rb +++ b/lib/mongo/server/round_trip_time_calculator.rb @@ -35,6 +35,7 @@ def initialize @last_round_trip_time = nil @average_round_trip_time = nil @minimum_round_trip_time = 0 + @lock = Mutex.new @rtts = [] end @@ -60,8 +61,10 @@ def measure # but we must not update the round trip time recorded in the server. unless exc @last_round_trip_time = last_rtt - update_average_round_trip_time - update_minimum_round_trip_time + @lock.synchronized do + update_average_round_trip_time + update_minimum_round_trip_time + end end if exc