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

If messages published failed with qos=0/1/2, what will mosquitto do? #1326

Open
ethsonliu opened this issue Jul 2, 2019 · 2 comments
Open

Comments

@ethsonliu
Copy link

ethsonliu commented Jul 2, 2019

I dit a test.

A client publish one message with length = 1024 bytes and qos = 1 every 1 second, meanwhile another client subscribe the same topic with the same qos level, and then write to mysql server.

step1: pull up the cable of publish-client for 30 minutes.
step2: reconnect the cable of the publish-client.
step3: wait 5 minutes to let publish-client to process(publish and republish the failed messages)
step4: check the saved datas of mysql server by the timestamp in each message's payload.

The conclusion is: mosquitto will save these published-failed-messages while network is broken, after the network reworks, mosquitto will republish these published-failed-messages, but maybe not all(it depends on the sum of bytes of all published-failed-messages or the number of all published-failed-messages, I guess).

So I looked into the source code of mosquitto, the flow of publishing is:

[exec mosquitto_publish()] --> [check the size of message] --> [if the size is valid, push_back to a mesages-linked-list].

In the net's loop, get the pointer of the first message from the list to publish, if publish success, remove it from list, and go to the next message; if failed, will not remove this message from this list.

You don't check the size of the current mesages-linked-list before exec push_back and the sum of bytes of all messages in this mesages-linked-list! This conflicted with my upper test. So, question one, why not to check?(if my upper analysis is right)

I want to add a feature into my client. If client publish failed with qos = 1 or 2, I will save them into local database, after network reworks, I'll republish and remove them from database manually.

But now it has some problems,

One: If publish failed with qos = 1, and after network reworks, both you and I will republish them, that is wasteful.

Two: If publish failed with qos = 2, and after network reworks, both you and I will republish them, this conflict with the definition of qos = 2.

So, my question two, is there a solution to stop your republish-action? (From my point, by removing from linked-list rather than still leaving them in linked-list when publish failed will solve this problem, and at the same time, this will be more friendly for developers.)

@ghost
Copy link

ghost commented Apr 21, 2020

@ethsonliu . Did you find any fix or workaround for this issue ?

@ethsonliu
Copy link
Author

@vishal000 Sry, no.

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

No branches or pull requests

1 participant