Skip to content

Commit 2b9366a

Browse files
authored
Merge pull request rails#51503 from Shopify/record-ping-on-every-actioncable-message
2 parents 84c4598 + 2a71de9 commit 2b9366a

File tree

6 files changed

+19
-12
lines changed

6 files changed

+19
-12
lines changed

actioncable/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
* Record ping on every actioncable message
2+
3+
Previously only `ping` and `welcome` message types were keeping connection active.
4+
Now every Action Cable message updates `pingedAt` value preventing connection from being marked as stale.
5+
6+
*yauhenininjia*
7+
18
* Add two new assertion methods for ActionCable test cases: `assert_has_no_stream`
29
and `assert_has_no_stream_for`. These methods can be used to assert that a
310
stream has been stopped, e.g. via `stop_stream` or `stop_stream_for`. They complement

actioncable/app/assets/javascripts/action_cable.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actioncable/app/assets/javascripts/actioncable.esm.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actioncable/app/assets/javascripts/actioncable.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actioncable/app/javascript/action_cable/connection.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ Connection.prototype.events = {
128128
message(event) {
129129
if (!this.isProtocolSupported()) { return }
130130
const {identifier, message, reason, reconnect, type} = JSON.parse(event.data)
131+
this.monitor.recordMessage()
131132
switch (type) {
132133
case message_types.welcome:
133134
if (this.triedToReconnect()) {
@@ -139,7 +140,7 @@ Connection.prototype.events = {
139140
logger.log(`Disconnecting. Reason: ${reason}`)
140141
return this.close({allowReconnect: reconnect})
141142
case message_types.ping:
142-
return this.monitor.recordPing()
143+
return null
143144
case message_types.confirmation:
144145
this.subscriptions.confirmSubscription(identifier)
145146
if (this.reconnectAttempted) {

actioncable/app/javascript/action_cable/connection_monitor.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,12 @@ class ConnectionMonitor {
3737
return this.startedAt && !this.stoppedAt
3838
}
3939

40-
recordPing() {
40+
recordMessage() {
4141
this.pingedAt = now()
4242
}
4343

4444
recordConnect() {
4545
this.reconnectAttempts = 0
46-
this.recordPing()
4746
delete this.disconnectedAt
4847
logger.log("ConnectionMonitor recorded connect")
4948
}

0 commit comments

Comments
 (0)