-
Notifications
You must be signed in to change notification settings - Fork 93
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
Manual ACK's, session state, and connection reestablishment #160
Comments
Since users have to bring their own connection, we don't deal with re-establishing connections at the For the sake of this discussion, I'm going to assume that |
Correct, but we do need to consider how the end users (or Session management gets tricky because the session state survives disconnection/reconnection so the lifecycle is differs from
This is exactly the problem. QOS2 = "Exactly once delivery"; if we redeliver a message that the client has already ACK'd then QOS2 becomes pretty much worthless. My point here is that an inbound QOS2 message should be delivered once; they should only be redelivered should the users application make the explicit decision not to ACK the message. |
After seeing the recent push for session persistence, I have attempted to migrate to autopaho and have run into this issue. Currently trying to assess a workaround but its non trivial. Our use case is a client that connects to a cluster, mqttv5 shared topics, auto reconnect, QOS 2, with manual ack, we also have session persistence on the cluster. This combo seems to be the only way to handle and ensure QOS 2. The v3 driver also lacks a reconnect option. Can I help? |
@ashtonian you are most welcome to help. My implementation is almost feature complete (ignore the readme, I need to find time to do some more testing and tidy things up a bit). I believe that the way I have implemented this will work with your setup (but it's not something I have tried) - perhaps you could assist with testing this under your environment?
|
didn't realize that supported ack() already, thanks, will test in qa |
It's not something I've really tested (but I believe it should work). Would really appreciate any feedback (I've added a lot more code than I would have liked but cannot see a better way of implementing this). I have file store code written and will try to push that out today (along with some bug fixes and additional tests). Hopefully over the weekend I'll get time to do some further testing (I'm sure there are bugs but need to decide how much time to spend before creating a PR as this is a large change!). |
@MattBrittan this is great work, thank you for this. Since this is still in beta, some bugs are acceptable, I think. If your implementation becomes the path forward for the project, I'd be willing to help work out any bugs that are found. I made a draft PR in my fork for the sake of providing feedback. Curious to hear your thoughts on what I said there. |
@vishnureddy17 - I'd really appreciate your review; have put a lot of work into this but struggling to find the time/motivation to finish it off (I think it's pretty much there but needs a bit more tidying/testing - I am conscious of the fact that the library is used in production in a number of code bases despite being pre 1.0 so want to be careful!). I've had a quick look at your comments but will be able to put more time into this next week (also keen to review with @alsm). |
Sounds good. If this does end up getting merged into here with a new release tag, I'll be using it for a project we're dogfooding internally at my company. Hopefully that can provide some real-world feedback if there are any issues or bugs. |
Testing out the fork. Couple of things I've noticed, not all to do with the fork.
|
Thanks very much for taking a look! (really keen to get feedback; I realise some tidying up in needed but want to prove the concept). I believe that these are all issues with the existing library (but see comments below) as opposed to being something introduced in the fork (so probably best to raising separate issues to track). I'm keen to land the fork before adding too many further changes (as adding persistence is a huge change).
Bug in current code (and also here). Probably should not start the pinger if keep alive is 0.
This would refer to
The
The v3 client |
RE: manual acks, another solution could be to have a reconnection counter and pass the value to the publish callback along with the publish packet. The For what it's worth, I think this is less elegant for the user than the two ideas proposed initially in this issue, but is a solution. |
paho would panic if keepalive was 0. Ref #160
Reflecting on comment I added to #185 Recent changes also provide a way for users (including
This means that the handler has access to the |
Whilst working on session state persistence I believe (happy to be proven wrong!) I have come across a small issue with the design of the
client
API so am raising it for discussion. I'm not sure how frequently manual acknowledgements are used (@fracasula this may be one for you?). Note that this is not currently an issue withautopaho
because it does not support manual acknowledgements (there is no way to callACK
).While this is a fairly niche issue I think it's important that we come up with a solution before v1 because I believe an API change will be required.
Consider the following situation:
client.ACK()
called (either on the old or the newclient
)There are issues here regardless of whether the session state survives the reconnection:
As mentioned above, the user may call
ACK
on the originalClient
or the new one; there are issues in both cases:CleanSession
) then sending the ACK may acknowledge a different message (as the server is free to reuse the ID).I guess we could just say "this is the users problem - they should use a waitgroup to track handlers and only reconnect when they have all completed" but I'm not sure that is the best option....
I cannot see a good way of handling this currently because there is currently no reliable way of working out which connection the
ACK
relates to. A couple of ways this could be solved are:NoAck
(or similar) function that indicates that the message will not be acknowledged. Then provide a way for the library to tell when all handlers have completed (i.e. eitherAck
orNoAck
have been called for all QOS1+ publish messages passed to the user) and only reconnect after that time.struct
passed toRouter.Route()
implementsAck()
and the user calls that instead ofclient.Ack()
. This would enable the library to prevent theAck
from being sent if the session was cleared (not a perfect solution as it's not really safe to assume a QOS1 resend is a duplicate).This is not a problem that impacts me personally (I don't use manual Acks) so I'm not intending to put much time into the issue and don't really have a preferred solution. Note that some of the above assumes that
paho
has a session state mechanism hat can outlast a connection (i.e. astruct
that is added toClientConfig
) - this is my current plan re managing session state.The text was updated successfully, but these errors were encountered: