File tree Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change 11# Unreleased
22
3+ - Fix ` Redis#close ` to properly reset the fork protection check.
4+
35# 5.0.1
46
57- Added a fake ` Redis::Connections.drivers ` method to be compatible with older sidekiq versions.
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ def sentinel(**kwargs)
3030 def initialize ( *)
3131 super
3232 @inherit_socket = false
33- @pid = Process . pid
33+ @pid = nil
3434 end
3535 ruby2_keywords :initialize if respond_to? ( :ruby2_keywords , true )
3636
@@ -114,10 +114,15 @@ def inherit_socket!
114114 @inherit_socket = true
115115 end
116116
117+ def close
118+ super
119+ @pid = nil
120+ end
121+
117122 private
118123
119124 def ensure_connected ( retryable : true )
120- unless @inherit_socket || Process . pid == @ pid
125+ unless @inherit_socket || ( @pid ||= Process . pid ) == Process . pid
121126 raise InheritedError ,
122127 "Tried to use a connection from a child process without reconnecting. " \
123128 "You need to reconnect to Redis after forking " \
Original file line number Diff line number Diff line change @@ -34,4 +34,17 @@ def test_mixed_encoding
3434 r . call ( "SET" , "\x00 \xFF " , "fée" )
3535 assert_equal "fée" , r . call ( "GET" , "\x00 \xFF " . b )
3636 end
37+
38+ def test_close_clear_pid
39+ assert_equal "PONG" , r . ping
40+ fake_pid = Process . pid + 1
41+ Process . stubs ( :pid ) . returns ( fake_pid )
42+
43+ assert_raises Redis ::InheritedError do
44+ r . ping
45+ end
46+
47+ r . close
48+ assert_equal "PONG" , r . ping
49+ end
3750end
You can’t perform that action at this time.
0 commit comments