-
Notifications
You must be signed in to change notification settings - Fork 725
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
on_publish called before on_connect #521
Comments
on_publish is tricky with QoS 0 messages, because we can only detect when the message has been passed to the OS, not when they have been accepted by the broker. So it will almost always fire before the broker can send a connack. I always recommend that actions go in the on_connect callback where possible, which would catch this, but it does seem that the expectation of synchronous connect() is that the connect/connack flow has occurred. This might be worth a wider discussion on the Paho mailing list, but I think something needs to be done. |
Hi @ralight; just noticed your comment on this issue (from a while ago!). I've recently commented on a few related issues (#454, #475, and a few questions on stack overflow) and can see other open issues with the same root cause. As you say above it looks like there is some confusion about the connection state when I'm happy to discuss on the mailing list; but given that this is a python specific question I was not sure if that was the best place. If you are in agreement I'll propose some updates to the documentation in an attempt to clarify this (I would think that changing the behaviour of |
Hi @MattBrittan, The idea of taking it to the mailing list would be to get a wider audience than is likely to see this. I agree with your points though - changing behaviour now is probably a bad idea and so documentation and examples are the way to help. If you want to suggest some updates I'd be very happy to see them. |
…n returns. As per discussion in issue eclipse-paho#521
Closing this because #615 has now been accepted which, hopefully, clarifies things a bit. If you feel more is needed then please feel free to reopen it. The MQTT protocol allows messages to be sent prior to a CONNACK being received; we could prevent that from happening but it's something that some users might want to do... |
I am trying to detect when a connection fails by checking the
CONNACK
in theon_connect
callback. In the case of a failure, I'm callingdisconnect
in theon_connect
callback to break the network loop. In order to also break the network loop when a connection is successful (e.g. in a case where I just want to publish and exit), I also calldisconnect
in theon_publish
callback.When the connection fails (specifically, connection refused due to authentication failure), the
on_publish
callback executes first and I am unable to catch the connection failure so all indications are that everything worked.As mentioned in issue #374,
on_publish
happens as soon as the packets are sent which here, appears to happen before theCONNACK
is received. The lack of reliable connection status and error notification seems to be a common problem. A few options would be very helpful.connect
truly synchronous instead of callingconnect_async
in all cases.on_connection_error
callback.If any of this is amenable to the maintainers, I'm happy to go through the Eclipse registration and submit pull requests.
The text was updated successfully, but these errors were encountered: