From 2cad173d1c2e4c9b9eefbf0954f653121937cc51 Mon Sep 17 00:00:00 2001 From: Dmitry Rybakov Date: Mon, 1 Jul 2024 16:32:58 +0200 Subject: [PATCH] Add synchronization --- lib/mongo/server/round_trip_time_calculator.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/mongo/server/round_trip_time_calculator.rb b/lib/mongo/server/round_trip_time_calculator.rb index 99ee7eb60e..5708dc2c95 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.synchronize do + update_average_round_trip_time + update_minimum_round_trip_time + end end if exc