So, after the last update all my connections on Android started dropping. Dug into it, and it was happening after the first ping like clockwork. It looks like the issue is due to differences between clock time at the server and the client app; they're being compared directly, but I don't think any work is being done to standardize across time zones (?), and given that a connection drops after 6 seconds even a very minor difference between the two computer's clocks would lead to healthCheck calling this.disconnect().
To demonstrate, just add a few prints to _handleProtocolMessage in the ping case;
switch (payload['type']) {
case 'ping':
// rails sends epoch as seconds not miliseconds
_lastPing =
DateTime.fromMillisecondsSinceEpoch(payload['message'] * 1000);
var localClockTime = DateTime.now();
print('setting ping time as _lastPing: $_lastPing');
print('localClockTime is ${localClockTime}');
print('initial difference should be zero, is actually: ${localClockTime.difference(_lastPing)}');
On Android with a local emulator I'm getting an initial difference of 40+ seconds and the disconnect is being called immediately; on iOS it's playing nicer 🤷
The simplest fix is to just set _lastPing to DateTime.now() when a ping message is received; that way, all timestamps being used on the client side in healthCheck are coming from the same client side clock. I'm new to action cable though, any issues with not tracking the state of the server time (as opposed to just duration between pings) that might come up?
Proposed fix:
void _handleProtocolMessage(Map payload) {
switch (payload['type']) {
case 'ping':
_lastPing = DateTime.now();
break;
So, after the last update all my connections on Android started dropping. Dug into it, and it was happening after the first ping like clockwork. It looks like the issue is due to differences between clock time at the server and the client app; they're being compared directly, but I don't think any work is being done to standardize across time zones (?), and given that a connection drops after 6 seconds even a very minor difference between the two computer's clocks would lead to
healthCheckcalling this.disconnect().To demonstrate, just add a few prints to
_handleProtocolMessagein thepingcase;On Android with a local emulator I'm getting an initial difference of 40+ seconds and the disconnect is being called immediately; on iOS it's playing nicer 🤷
The simplest fix is to just set _lastPing to DateTime.now() when a ping message is received; that way, all timestamps being used on the client side in
healthCheckare coming from the same client side clock. I'm new to action cable though, any issues with not tracking the state of the server time (as opposed to just duration between pings) that might come up?Proposed fix: