-
Notifications
You must be signed in to change notification settings - Fork 534
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
Return token with an error when Publish has failed due to lost connection #450
Conversation
…tion Signed-off-by: oleksmir <olexiy.miroshnik@gmail.com>
@alsm @MattBrittan Please, take a look. |
Unfortunately this library has a lot of options and the logic can be somewhat convoluted... In many instances (on connection if In some other circumstances In terms of
My concern is that I think that this does change the logic somewhat. Generally something that goes wrong after the outgoing message is persisted is not considered to be an error (this predates my involvement but I guess the logic is that the message will be delivered eventually). So (with I suspect that I have missed something in the above (or not fully understood what you are trying to accomplish) but hopefully the above helps set the scene a bit. Note: I do not have commit rights to this project (believe that @alsm is currently the only active committer). |
Thank you @MattBrittan for the quick response.
The problem here is that token is never persisted to the store. According to the source code of the publish method, we create a token besides the publish packet. The binding between packet and token is taking place on this line: case c.obound <- &PacketAndToken{p: pub, t: token}: and works for the If the connection in the Maybe I am missing something but I did not get the way token can be restored and completed as 'old'. Even if the connection is reestablished, the code is continue being locked on the |
The token should be persisted here :
As the message has also been allocated an id the token is in the message id map and, as such, As you say if the connection status is
Here is a run through (doing this to ensure I understand it as much as to communicate it to you); note that some of this depends upon your options which can make diagnosis without sample code difficult:
So I think that this covers off storing the message, re-sending after the reconnection and freeing existing tokens. However I do have a niggling feeling that there is a bug in there somewhere (We probably should be doing the Note: The whole token system is somewhat problematic which is why @alsm has dropped it in the MQTT v5 client. |
@MattBrittan Thank you for the detailed explanation. Much appreciate. |
After the
Publish
method is invoked, it is possible a situation when the paho client can be in aconnecting
orreconnecting
state. Thus, the returned token will never be completed because nobody invokes theflowComplete
method. When a connection is reestablished, this token is not revoked or recreated internally.On the consumer/client side it will be a problem if the client invokes
token.Wait()
. Even withWriteTimeout
client settings this invocation will never end and lead client code to be stuck. One of the possible solutions is to usetoken.WaitTimeout()
that forces our client to manually check token status until reconnect is finished but even with this approach, you cannot get the completed flow.Still, my code wants to have guarantees about message delivery and handling. In this case, I want to continue working with a
token.Wait()
and be possible to interrupt invocation by tuning up theWaitTimeout
setting.This PR proposes to complete token flow if the current connection status is
connecting
orreconnecting
. To notify the client about publishing problems it uses custom errors that can be checked by the invocation side. If an error has occurred, we guarantee that the outbound message was persisted inside the internal storage and will be delivered as soon as the connection is reestablished. Thus, this PR does not modify the logic of thePublish
method, just fixes an issue with uncompleted token andPublish
unlock.