Skip to content

Commit 4becc93

Browse files
committed
don't update the service timeout again if we're over the limit
refs CNVS-8371 test plan: * trigger 3 ldap timeouts, see test plan in c17f357 * you'll be blocked from further ldap attempts for 1 minute. after that minute passes, verify that canvas starts making ldap attempts again. Change-Id: I8ac6b74bd75f6f3e18deaf3a1fabd01fb867c26e Reviewed-on: https://gerrit.instructure.com/25047 Reviewed-by: Rob Orton <rob@instructure.com> Tested-by: Brian Palmer <brianp@instructure.com> QA-Review: August Thornton <august@instructure.com> Product-Review: Brian Palmer <brianp@instructure.com>
1 parent d71df3d commit 4becc93

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

lib/canvas.rb

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,20 @@ def self.timeout_protection(service_name, options={})
148148
end
149149

150150
timeout = (Setting.get_cached("service_#{service_name}_timeout", nil) || options[:fallback_timeout_length] || Setting.get_cached("service_generic_timeout", 15.seconds.to_s)).to_f
151-
Timeout.timeout(timeout) do
152-
yield
153-
end
154-
rescue Timeout::Error => e
155-
ErrorReport.log_exception(:service_timeout, e)
156-
if Canvas.redis_enabled?
157-
error_ttl = (Setting.get_cached("service_#{service_name}_error_ttl", nil) || Setting.get_cached("service_generic_error_ttl", 1.minute.to_s)).to_i
158-
Canvas.redis.incrby(redis_key, 1)
159-
Canvas.redis.expire(redis_key, error_ttl)
151+
152+
begin
153+
Timeout.timeout(timeout) do
154+
yield
155+
end
156+
rescue Timeout::Error => e
157+
ErrorReport.log_exception(:service_timeout, e)
158+
if Canvas.redis_enabled?
159+
error_ttl = (Setting.get_cached("service_#{service_name}_error_ttl", nil) || Setting.get_cached("service_generic_error_ttl", 1.minute.to_s)).to_i
160+
Canvas.redis.incrby(redis_key, 1)
161+
Canvas.redis.expire(redis_key, error_ttl)
162+
end
163+
raise if options[:raise_on_timeout]
164+
return nil
160165
end
161-
raise if options[:raise_on_timeout]
162-
return nil
163166
end
164167
end

spec/lib/canvas_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
it "should raise on cutoff if raise_on_timeout option is specified" do
7676
Canvas.redis.set("service:timeouts:spec", 42)
7777
lambda { Canvas.timeout_protection("spec", raise_on_timeout: true) {} }.should raise_error(Timeout::Error)
78+
Canvas.redis.get("service:timeouts:spec").should == "42"
7879
end
7980
end
8081
end

0 commit comments

Comments
 (0)