Skip to content

Commit 9352f58

Browse files
p-mongop
andcommitted
RUBY-2806 Rate limit push monitor handshake sends (#2357)
Co-authored-by: Oleg Pudeyev <[email protected]>
1 parent 012e79f commit 9352f58

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/mongo/server/push_monitor.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ def do_work
123123
log_prefix: options[:log_prefix],
124124
bg_error_backtrace: options[:bg_error_backtrace],
125125
)
126+
127+
# Avoid tight looping in push monitor - see RUBY-2806.
128+
sleep(0.5)
126129
end
127130

128131
def check

spec/mongo/server/push_monitor_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,25 @@
7676
push_monitor.do_work
7777
end.should_not raise_error
7878
end
79+
80+
it 'throttles checks' do
81+
push_monitor
82+
83+
start = Mongo::Utils.monotonic_time
84+
85+
expect(Socket).to receive(:getaddrinfo).and_raise(SocketError.new('Test exception'))
86+
lambda do
87+
push_monitor.do_work
88+
end.should_not raise_error
89+
90+
expect(Socket).to receive(:getaddrinfo).and_raise(SocketError.new('Test exception'))
91+
lambda do
92+
push_monitor.do_work
93+
end.should_not raise_error
94+
95+
elapsed = Mongo::Utils.monotonic_time - start
96+
elapsed.should > 0.5
97+
end
7998
end
8099
end
81100

0 commit comments

Comments
 (0)