Skip to content

Commit

Permalink
Merge branch 'master' into track-missed-heartbeats
Browse files Browse the repository at this point in the history
  • Loading branch information
achilleasa authored Jan 4, 2024
2 parents ff88b28 + 6cdc538 commit fd85301
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/src/client/impl/client_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ class _ClientImpl implements Client {
// heartbeats.
Duration missInterval =
tuningSettings.heartbeatPeriod * tuningSettings.maxMissedHeartbeats;
_heartbeatRecvTimer = RestartableTimer(missInterval, () {
_heartbeatRecvTimer?.cancel();
_heartbeatRecvTimer =
RestartableTimer(tuningSettings.heartbeatPeriod, () {
// Set the timer to null to avoid accidentally resetting it while
// shutting down.
_heartbeatRecvTimer = null;
Expand Down Expand Up @@ -222,7 +224,7 @@ class _ClientImpl implements Client {
if (handshaking) {
_channels.clear();
_connected!.completeError(ex);
close();
_close();
return;
}

Expand All @@ -241,7 +243,7 @@ class _ClientImpl implements Client {
.reversed
.forEach((_ChannelImpl channel) => channel.handleException(ex));

close();
_close();
break;
case ChannelException:
// Forward to the appropriate channel and remove it from our list
Expand Down Expand Up @@ -273,6 +275,13 @@ class _ClientImpl implements Client {
/// when the client has shut down
@override
Future close() {
return _close(closeErrorStream: true);
}

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

if (_socket == null) {
return Future.value();
}
Expand All @@ -295,7 +304,9 @@ class _ClientImpl implements Client {
_socket!.destroy();
_socket = null;
_connected = null;
_error.close();
if (closeErrorStream) {
_error.close();
}
_clientClosed!.complete();
_clientClosed = null;
});
Expand Down

0 comments on commit fd85301

Please sign in to comment.