Skip to content

Commit 6e9304a

Browse files
authored
Merge pull request rails#43086 from nstuart-at-salesforce/nas_addRaiseErrorsParam
Removed rescue block from `ActiveSupport::Cache::RedisCacheStore#handle_exception`
2 parents 94e8026 + aabc27f commit 6e9304a

File tree

6 files changed

+172
-2
lines changed

6 files changed

+172
-2
lines changed

activesupport/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
* Removed rescue block from `ActiveSupport::Cache::RedisCacheStore#handle_exception`
2+
3+
Previously, if you provided a `error_handler` to `redis_cache_store`, any errors thrown by
4+
the error handler would be rescued and logged only. Removed the `rescue` clause from `handle_exception`
5+
to allow these to be thrown.
6+
7+
*Nicholas A. Stuart*
8+
19
* Allow entirely opting out of deprecation warnings.
210

311
Previously if you did `app.config.active_support.deprecation = :silence`, some work would

activesupport/lib/active_support/cache/redis_cache_store.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,6 @@ def handle_exception(exception:, method:, returning:)
467467
if @error_handler
468468
@error_handler.(method: method, exception: exception, returning: returning)
469469
end
470-
rescue => failsafe
471-
warn "RedisCacheStore ignored exception in handle_exception: #{failsafe.class}: #{failsafe.message}\n #{failsafe.backtrace.join("\n ")}"
472470
end
473471
end
474472
end

activesupport/test/cache/behaviors.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
require_relative "behaviors/connection_pool_behavior"
1010
require_relative "behaviors/encoded_key_cache_behavior"
1111
require_relative "behaviors/failure_safety_behavior"
12+
require_relative "behaviors/failure_raising_behavior"
1213
require_relative "behaviors/local_cache_behavior"
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# frozen_string_literal: true
2+
3+
module FailureRaisingBehavior
4+
def test_fetch_read_failure_raises
5+
@cache.write("foo", "bar")
6+
7+
assert_raise Redis::BaseError do
8+
emulating_unavailability do |cache|
9+
cache.fetch("foo")
10+
end
11+
end
12+
end
13+
14+
def test_fetch_with_block_read_failure_raises
15+
@cache.write("foo", "bar")
16+
17+
assert_raise Redis::BaseError do
18+
emulating_unavailability do |cache|
19+
cache.fetch("foo") { "1" }
20+
end
21+
end
22+
23+
assert_equal "bar", @cache.read("foo")
24+
end
25+
26+
def test_read_failure_raises
27+
@cache.write("foo", "bar")
28+
29+
assert_raise Redis::BaseError do
30+
emulating_unavailability do |cache|
31+
cache.read("foo")
32+
end
33+
end
34+
end
35+
36+
def test_read_multi_failure_raises
37+
@cache.write_multi("foo" => "bar", "baz" => "quux")
38+
39+
assert_raise Redis::BaseError do
40+
emulating_unavailability do |cache|
41+
cache.read_multi("foo", "baz")
42+
end
43+
end
44+
end
45+
46+
def test_write_failure_raises
47+
assert_raise Redis::BaseError do
48+
emulating_unavailability do |cache|
49+
cache.write("foo", "bar")
50+
end
51+
end
52+
end
53+
54+
def test_write_multi_failure_raises
55+
assert_raise Redis::BaseError do
56+
emulating_unavailability do |cache|
57+
cache.write_multi("foo" => "bar", "baz" => "quux")
58+
end
59+
end
60+
end
61+
62+
def test_fetch_multi_failure_raises
63+
@cache.write_multi("foo" => "bar", "baz" => "quux")
64+
65+
assert_raise Redis::BaseError do
66+
emulating_unavailability do |cache|
67+
cache.fetch_multi("foo", "baz") { |k| "unavailable" }
68+
end
69+
end
70+
end
71+
72+
def test_delete_failure_raises
73+
@cache.write("foo", "bar")
74+
75+
assert_raise Redis::BaseError do
76+
emulating_unavailability do |cache|
77+
cache.delete("foo")
78+
end
79+
end
80+
end
81+
82+
def test_exist_failure_raises
83+
@cache.write("foo", "bar")
84+
85+
assert_raise Redis::BaseError do
86+
emulating_unavailability do |cache|
87+
cache.exist?("foo")
88+
end
89+
end
90+
end
91+
92+
def test_increment_failure_raises
93+
@cache.write("foo", 1, raw: true)
94+
95+
assert_raise Redis::BaseError do
96+
emulating_unavailability do |cache|
97+
cache.increment("foo")
98+
end
99+
end
100+
end
101+
102+
def test_decrement_failure_raises
103+
@cache.write("foo", 1, raw: true)
104+
105+
assert_raise Redis::BaseError do
106+
emulating_unavailability do |cache|
107+
cache.decrement("foo")
108+
end
109+
end
110+
end
111+
112+
def test_clear_failure_returns_nil
113+
assert_raise Redis::BaseError do
114+
emulating_unavailability do |cache|
115+
cache.clear
116+
end
117+
end
118+
end
119+
end

activesupport/test/cache/behaviors/failure_safety_behavior.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ def test_fetch_read_failure_returns_nil
1010
end
1111

1212
def test_fetch_read_failure_does_not_attempt_to_write
13+
@cache.write("foo", "bar")
14+
15+
emulating_unavailability do |cache|
16+
val = cache.fetch("foo") { "1" }
17+
18+
##
19+
# Though the `write` part of fetch fails for the same reason
20+
# `read` will, the block result is still executed and returned.
21+
assert_equal "1", val
22+
end
23+
24+
assert_equal "bar", @cache.read("foo")
1325
end
1426

1527
def test_read_failure_returns_nil

activesupport/test/cache/stores/redis_cache_store_test.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,38 @@ def ensure_connected
283283
end
284284
end
285285

286+
class FailureRaisingFromUnavailableClientTest < StoreTest
287+
include FailureRaisingBehavior
288+
289+
private
290+
def emulating_unavailability
291+
old_client = Redis.send(:remove_const, :Client)
292+
Redis.const_set(:Client, UnavailableRedisClient)
293+
294+
yield ActiveSupport::Cache::RedisCacheStore.new(namespace: @namespace,
295+
error_handler: -> (method:, returning:, exception:) { raise exception })
296+
ensure
297+
Redis.send(:remove_const, :Client)
298+
Redis.const_set(:Client, old_client)
299+
end
300+
end
301+
302+
class FailureRaisingFromMaxClientsReachedErrorTest < StoreTest
303+
include FailureRaisingBehavior
304+
305+
private
306+
def emulating_unavailability
307+
old_client = Redis.send(:remove_const, :Client)
308+
Redis.const_set(:Client, MaxClientsReachedRedisClient)
309+
310+
yield ActiveSupport::Cache::RedisCacheStore.new(namespace: @namespace,
311+
error_handler: -> (method:, returning:, exception:) { raise exception })
312+
ensure
313+
Redis.send(:remove_const, :Client)
314+
Redis.const_set(:Client, old_client)
315+
end
316+
end
317+
286318
class FailureSafetyFromUnavailableClientTest < StoreTest
287319
include FailureSafetyBehavior
288320

0 commit comments

Comments
 (0)