Skip to content
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

Corrected Cancellation Source for KeepAlive Messages #2129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Erw1nT
Copy link

@Erw1nT Erw1nT commented Dec 18, 2024

I found out that the issue found in #2108 likely comes due to the fact that the wrong duration is used for checking the keep alive interval.

In this test setup i connect to a public broker and use the approach described in #2108 to see if it is triggered within time.
https://github.com/Erw1nT/MqttKeepAlive/blob/master/Program.cs

Only when this line is added, the connection-changed/disconnected event is fired in time.

.WithTimeout(TimeSpan.FromSeconds(KeepAliveTimeInSeconds))

{
timeoutCancellationTokenSource.CancelAfter(Options.Timeout);
await PingAsync(timeoutCancellationTokenSource.Token).ConfigureAwait(false);
keepAliveCancellationTokenSource.CancelAfter(keepAlivePeriod);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change the cancellation will happen earlier according to the keep alive period (15 seconds). Which is by default way smaller than the generic communication timeout (100 seconds).

But we already reached timeWithoutPacketSent > keepAlivePeriod so that wait an additional of 15 seconds (so 30 in total).

Isn't it a better way to wait for keepAlivePeriod / 2 to match the calculation at the server instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants