From 9b549278f83a7abd48f3b3624249d32589d67bc5 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..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