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 1
1
# Unreleased
2
2
3
+ - Fix ` Redis#close ` to properly reset the fork protection check.
4
+
3
5
# 5.0.1
4
6
5
7
- 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)
30
30
def initialize ( *)
31
31
super
32
32
@inherit_socket = false
33
- @pid = Process . pid
33
+ @pid = nil
34
34
end
35
35
ruby2_keywords :initialize if respond_to? ( :ruby2_keywords , true )
36
36
@@ -114,10 +114,15 @@ def inherit_socket!
114
114
@inherit_socket = true
115
115
end
116
116
117
+ def close
118
+ super
119
+ @pid = nil
120
+ end
121
+
117
122
private
118
123
119
124
def ensure_connected ( retryable : true )
120
- unless @inherit_socket || Process . pid == @ pid
125
+ unless @inherit_socket || ( @pid ||= Process . pid ) == Process . pid
121
126
raise InheritedError ,
122
127
"Tried to use a connection from a child process without reconnecting. " \
123
128
"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
34
34
r . call ( "SET" , "\x00 \xFF " , "fée" )
35
35
assert_equal "fée" , r . call ( "GET" , "\x00 \xFF " . b )
36
36
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
37
50
end
You can’t perform that action at this time.
0 commit comments