actioncable 7.0.4.3 → 7.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2622a0bda2ac4e21aef9acb2345a385ddcb76b9623b0880b81ebef1b135eb1d1
4
- data.tar.gz: f0065045a66e532260bff962f925ae844b230160a1d1e07f33bcbc774941206d
3
+ metadata.gz: 0ad111921f6a4ec24d48066344c243f71246f073d036614075354cd332369c69
4
+ data.tar.gz: dbfddf4a0a3839c9f093dbb54b04038d3e805c00d06dc00b0716eb598d37dec8
5
5
  SHA512:
6
- metadata.gz: 5f6d3cf4c904c9213e901235c310f12b416a2fcb7570f859463f932fc15b2831988cc8cddf0e4d45d19571143a3cddd19bf9683f35f092cf363f4dcc2eec2506
7
- data.tar.gz: edf288bef934a10d639748750277edd2c8ecf1b4d4cee650bfd8bbd43517923417083f6cc2860f52acb2d0e99c3cb976118dc66e62b180f7cea61669d2503b2a
6
+ metadata.gz: 5b7ccdd8a695955ca21d16a49eaa369228e177bef683ecd159f51d94f3d8860e4bf6121561f5dc52b7e37b46e40714876d3326f51c20d604f67770ebd11e3665
7
+ data.tar.gz: 19d2b1d7c252454069a8002e61d06371ac518e043e00fef0e8effab28fea0d424c43968923670c06c569ef64fe2871bb912c22908d1fa027fb873f075456eb9d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## Rails 7.0.5 (May 24, 2023) ##
2
+
3
+ * Restore Action Cable Redis pub/sub listener on connection failure.
4
+
5
+ *Vladimir Dementyev*
6
+
7
+
1
8
  ## Rails 7.0.4.3 (March 13, 2023) ##
2
9
 
3
10
  * No changes.
@@ -9,8 +9,8 @@ module ActionCable
9
9
  module VERSION
10
10
  MAJOR = 7
11
11
  MINOR = 0
12
- TINY = 4
13
- PRE = "3"
12
+ TINY = 5
13
+ PRE = nil
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
16
16
  end
@@ -46,7 +46,7 @@ module ActionCable
46
46
 
47
47
  private
48
48
  def listener
49
- @listener || @server.mutex.synchronize { @listener ||= Listener.new(self, @server.event_loop) }
49
+ @listener || @server.mutex.synchronize { @listener ||= Listener.new(self, config_options, @server.event_loop) }
50
50
  end
51
51
 
52
52
  def redis_connection_for_broadcasts
@@ -56,11 +56,15 @@ module ActionCable
56
56
  end
57
57
 
58
58
  def redis_connection
59
- self.class.redis_connector.call(@server.config.cable.symbolize_keys.merge(id: identifier))
59
+ self.class.redis_connector.call(config_options)
60
+ end
61
+
62
+ def config_options
63
+ @config_options ||= @server.config.cable.symbolize_keys.merge(id: identifier)
60
64
  end
61
65
 
62
66
  class Listener < SubscriberMap
63
- def initialize(adapter, event_loop)
67
+ def initialize(adapter, config_options, event_loop)
64
68
  super()
65
69
 
66
70
  @adapter = adapter
@@ -69,6 +73,11 @@ module ActionCable
69
73
  @subscribe_callbacks = Hash.new { |h, k| h[k] = [] }
70
74
  @subscription_lock = Mutex.new
71
75
 
76
+ @reconnect_attempt = 0
77
+ # Use the same config as used by Redis conn
78
+ @reconnect_attempts = config_options.fetch(:reconnect_attempts, 1)
79
+ @reconnect_attempts = Array.new(@reconnect_attempts, 0) if @reconnect_attempts.is_a?(Integer)
80
+
72
81
  @subscribed_client = nil
73
82
 
74
83
  @when_connected = []
@@ -84,6 +93,7 @@ module ActionCable
84
93
  on.subscribe do |chan, count|
85
94
  @subscription_lock.synchronize do
86
95
  if count == 1
96
+ @reconnect_attempt = 0
87
97
  @subscribed_client = original_client
88
98
 
89
99
  until @when_connected.empty?
@@ -150,8 +160,16 @@ module ActionCable
150
160
  @thread ||= Thread.new do
151
161
  Thread.current.abort_on_exception = true
152
162
 
153
- conn = @adapter.redis_connection_for_subscriptions
154
- listen conn
163
+ begin
164
+ conn = @adapter.redis_connection_for_subscriptions
165
+ listen conn
166
+ rescue ConnectionError
167
+ reset
168
+ if retry_connecting?
169
+ when_connected { resubscribe }
170
+ retry
171
+ end
172
+ end
155
173
  end
156
174
  end
157
175
 
@@ -163,7 +181,36 @@ module ActionCable
163
181
  end
164
182
  end
165
183
 
184
+ def retry_connecting?
185
+ @reconnect_attempt += 1
186
+
187
+ return false if @reconnect_attempt > @reconnect_attempts.size
188
+
189
+ sleep_t = @reconnect_attempts[@reconnect_attempt - 1]
190
+
191
+ sleep(sleep_t) if sleep_t > 0
192
+
193
+ true
194
+ end
195
+
196
+ def resubscribe
197
+ channels = @sync.synchronize do
198
+ @subscribers.keys
199
+ end
200
+ @subscribed_client.subscribe(*channels) unless channels.empty?
201
+ end
202
+
203
+ def reset
204
+ @subscription_lock.synchronize do
205
+ @subscribed_client = nil
206
+ @subscribe_callbacks.clear
207
+ @when_connected.clear
208
+ end
209
+ end
210
+
166
211
  if ::Redis::VERSION < "5"
212
+ ConnectionError = ::Redis::ConnectionError
213
+
167
214
  class SubscribedClient
168
215
  def initialize(raw_client)
169
216
  @raw_client = raw_client
@@ -197,6 +244,8 @@ module ActionCable
197
244
  SubscribedClient.new(raw_client)
198
245
  end
199
246
  else
247
+ ConnectionError = RedisClient::ConnectionError
248
+
200
249
  def extract_subscribed_client(conn)
201
250
  conn
202
251
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actioncable
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.4.3
4
+ version: 7.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pratik Naik
8
8
  - David Heinemeier Hansson
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-03-13 00:00:00.000000000 Z
12
+ date: 2023-05-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -17,28 +17,28 @@ dependencies:
17
17
  requirements:
18
18
  - - '='
19
19
  - !ruby/object:Gem::Version
20
- version: 7.0.4.3
20
+ version: 7.0.5
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - '='
26
26
  - !ruby/object:Gem::Version
27
- version: 7.0.4.3
27
+ version: 7.0.5
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: actionpack
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - '='
33
33
  - !ruby/object:Gem::Version
34
- version: 7.0.4.3
34
+ version: 7.0.5
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - '='
40
40
  - !ruby/object:Gem::Version
41
- version: 7.0.4.3
41
+ version: 7.0.5
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: nio4r
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -142,12 +142,12 @@ licenses:
142
142
  - MIT
143
143
  metadata:
144
144
  bug_tracker_uri: https://github.com/rails/rails/issues
145
- changelog_uri: https://github.com/rails/rails/blob/v7.0.4.3/actioncable/CHANGELOG.md
146
- documentation_uri: https://api.rubyonrails.org/v7.0.4.3/
145
+ changelog_uri: https://github.com/rails/rails/blob/v7.0.5/actioncable/CHANGELOG.md
146
+ documentation_uri: https://api.rubyonrails.org/v7.0.5/
147
147
  mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
148
- source_code_uri: https://github.com/rails/rails/tree/v7.0.4.3/actioncable
148
+ source_code_uri: https://github.com/rails/rails/tree/v7.0.5/actioncable
149
149
  rubygems_mfa_required: 'true'
150
- post_install_message:
150
+ post_install_message:
151
151
  rdoc_options: []
152
152
  require_paths:
153
153
  - lib
@@ -162,8 +162,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
162
  - !ruby/object:Gem::Version
163
163
  version: '0'
164
164
  requirements: []
165
- rubygems_version: 3.4.3
166
- signing_key:
165
+ rubygems_version: 3.4.10
166
+ signing_key:
167
167
  specification_version: 4
168
168
  summary: WebSocket framework for Rails.
169
169
  test_files: []