mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-24 14:43:04 +08:00
Corrected Cancellation Source for KeepAlive Messages (#2129)
* Corrected Cancellation Source for KeepAlive Messages * Use half of the keep alive value for the ping timeout * Update release notes * Update ReleaseNotes.md * Update ReleaseNotes.md * Update ReleaseNotes.md --------- Co-authored-by: christian <6939810+chkr1011@users.noreply.github.com>
This commit is contained in:
@@ -1041,11 +1041,13 @@ public sealed class MqttClient : Disposable, IMqttClient
|
||||
|
||||
if (timeWithoutPacketSent > keepAlivePeriod)
|
||||
{
|
||||
using (var timeoutCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken))
|
||||
{
|
||||
timeoutCancellationTokenSource.CancelAfter(Options.Timeout);
|
||||
await PingAsync(timeoutCancellationTokenSource.Token).ConfigureAwait(false);
|
||||
}
|
||||
using var pingTimeout = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
|
||||
|
||||
// We already reached the keep alive timeout. Due to the RFC part [MQTT-3.1.2-24] the server will wait another
|
||||
// 1/2 of the keep alive time. So we can also use this value as the timeout.
|
||||
pingTimeout.CancelAfter(keepAlivePeriod / 2);
|
||||
|
||||
await PingAsync(pingTimeout.Token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// Wait a fixed time in all cases. Calculation of the remaining time is complicated
|
||||
|
||||
Reference in New Issue
Block a user