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

Auto-reconnect documenation and samples are a bit confusing #1945

Open
vypsim opened this issue Mar 5, 2024 · 0 comments
Open

Auto-reconnect documenation and samples are a bit confusing #1945

vypsim opened this issue Mar 5, 2024 · 0 comments
Labels
question It is a question regarding the project

Comments

@vypsim
Copy link

vypsim commented Mar 5, 2024

Hi, the documentation for how to auto reconnect, when connection fails, is confusing. I'd appreciate it if I can get some clarification on the questions below.

First of all, the Wiki is referencing a method that no longer exists, which will lead developers to the samples below.

Reconnect_Using_Event Sample

The sample states:

This approach has a risk of dead locks! Consider using the timer approach (see sample).

But the comment in MqttClient.cs, where the Disconnected event is raised, says that it's wrapped in a Task.Run(...) to avoid dead-locks.

Q1) Is running in a separate thread not enough and it may end up in a dead-lock anyway? or should the samples be updated and that comment removed to avoid confusion?

Reconnect_Using_Timer Sample

The sample recommends calling TryPingAsync in a loop which seems incorrect after looking at the code in MqttClient.cs since the client internally maintains a keep alive loop where it pings the server and updates the connection status (IsConnected) accordingly. And it does it in a way that's better than a simple loop with TryPingAsync because it takes into consideration whether packets have been exchanged succesfully and thus avoids the extra pings.
And more to this point, when looking at ManagedMqttClient which has a timer loop, it doesn't call Ping at all, but instead checks IsConnected

Q2) Is Reconnect_Using_Timer sample misleading and inefficient or have I missed something?

@vypsim vypsim added the question It is a question regarding the project label Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question It is a question regarding the project
Projects
None yet
Development

No branches or pull requests

1 participant