Skip to content

Commit

Permalink
Merge pull request #95 from achilleasa/skip-hearbeats-for-closed-chan…
Browse files Browse the repository at this point in the history
…nels

Guard against sending heartbeats if the underlying socket is closed
  • Loading branch information
achilleasa authored Mar 9, 2023
2 parents fbdad23 + 7e6103e commit 1f339fb
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/src/client/impl/channel_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,21 @@ class _ChannelImpl implements Channel {
}

void writeHeartbeat() {
if (_channelClosed != null || _client._socket == null) {
return; // no-op
}

// Transmit heartbeat
_frameWriter
..writeHeartbeat()
..pipe(_client._socket!);
try {
_frameWriter
..writeHeartbeat()
..pipe(_client._socket!);
} catch (_) {
// An exception will be raised if we attempt to send a hearbeat
// immediately after the connection to the server is lost. We can safely
// ignore this error; clients will be notified of the lost connection via
// a raised StateError.
}
}

/// Encode and transmit [message] optionally accompanied by a server frame with [payloadContent].
Expand Down

0 comments on commit 1f339fb

Please sign in to comment.