Skip to content

Commit

Permalink
Reset heartbeat timer when attempting to reconnect
Browse files Browse the repository at this point in the history
This commit fixes a bug in the reconnect handling code where the client
would overwrite a pre-existing heartbeat timer without first cancelling
it. As a result, the old timer would eventually fire and trigger a
HeartbeatFailedException closing the connection.
achilleasa committed Jan 2, 2024
1 parent b4dab3b commit 932f748
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/src/client/impl/client_impl.dart
Original file line number Diff line number Diff line change
@@ -138,6 +138,7 @@ class _ClientImpl implements Client {
// period has been configured, start monitoring incoming heartbeats.
if (serverMessage.message is ConnectionOpenOk &&
tuningSettings.heartbeatPeriod.inSeconds > 0) {
_heartbeatRecvTimer?.cancel();
_heartbeatRecvTimer =
RestartableTimer(tuningSettings.heartbeatPeriod, () {
// Set the timer to null to avoid accidentally resetting it while
@@ -269,6 +270,9 @@ class _ClientImpl implements Client {
}

Future _close({bool closeErrorStream = false}) {
_heartbeatRecvTimer?.cancel();
_heartbeatRecvTimer = null;

if (_socket == null) {
return Future.value();
}

0 comments on commit 932f748

Please sign in to comment.