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

ManagedMqttClient Issue with sending message just after Start. #1849

Open
pdufrene opened this issue Sep 26, 2023 · 4 comments
Open

ManagedMqttClient Issue with sending message just after Start. #1849

pdufrene opened this issue Sep 26, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@pdufrene
Copy link
Contributor

pdufrene commented Sep 26, 2023

Hello,

Describe the bug

I have the following case:
One server, one client (producer), another client (consumer).
I start the server.
I start the producer and I send immediately a message with retain flag.
I start the consumer and subscribe to the topic.

I am facing a strange behavior where sometimes, the retained message is not received by the consumer.

I am able to work around if I add a Task.Delay(1) between the start of producer and the enqueue of the message.

Which component is your bug related to?

  • ManagedClient v4.3.1.873

To Reproduce

Open the attached visual studio solution, execute the unit tests.
There is 2 tests, one where the server is restarted at each loop, another where the server is started only once.
I have Theory, (one with Task.Delay(0) failing, one with Task.Delay(1) success)

Expected behavior

A reproducible behavior without Task.Delay or a way to be sure that initialization is ok.

Code example

See attached solution.

MqttNetTester.zip

@pdufrene pdufrene added the bug Something isn't working label Sep 26, 2023
@pdufrene pdufrene changed the title ManagedMqttClient Issue with sending message just after Start.l ManagedMqttClient Issue with sending message just after Start. Sep 27, 2023
@rabejens
Copy link

I have a similar problem. I am using the server and the client in an XUnit test, and in my test method, I get very erratic behavior.

With waiting for half a second after starting the client and after subscribing, I receive messages about half the time. Currently, my solution is to ditch the managed client and use the unmanaged one, implementing the reconnection logic myself.

@pdufrene
Copy link
Contributor Author

The point is that I am facing similar issue in my normal execution environment (Windows 10 Machine) in some rare cases.
This is why I started to isolate the issue using unit tests, but I now realize that XUnit execution is maybe not behaving in same way that normal execution. (Specially on Task management).

I'll try with a regular console application.

@pdufrene
Copy link
Contributor Author

pdufrene commented Oct 5, 2023

While testing with external broker (Mosquitto in that case) I don't have the issue, the code works perfectly without Task.Delay.
So I am presuming the issue is in Server part. I saw from the logs that some task are not stopped before a certain amount of time, may be it's related.
@chkr1011 any advice on that ?

@kdurkin77
Copy link

Any update on this? I'm having a very similar issue where I need about a half a second delay between starting the managed client and subscribing or I miss messages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants