Skip to content

Corrected Cancellation Source for KeepAlive Messages #2129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions Source/MQTTnet/MqttClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1041,11 +1041,13 @@ async Task TrySendKeepAliveMessages(CancellationToken cancellationToken)

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
Expand Down
1 change: 1 addition & 0 deletions Source/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Client: MQTT 5.0.0 is now the default version when connecting with a server **(BREAKING CHANGE)**
* Client: Fixed enhanced authentication.
* Client: Exposed WebSocket compression options in MQTT client options (thanks to @victornor, #2127)
* Client: Fixed wrong timeout for keep alive check (thanks to @Erw1nT, #2129)
* Server: Fixed enhanced authentication.
* Server: Set default for "MaxPendingMessagesPerClient" to 1000 **(BREAKING CHANGE)**
* Server: Set SSL version to "None" which will let the OS choose the version **(BREAKING CHANGE)**
Expand Down