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

[samples][async_subscribe] Connect or disconnect command ignored When systemctl restart mosquitto.service #432

Open
YeahhhhLi opened this issue Apr 11, 2023 · 0 comments

Comments

@YeahhhhLi
Copy link

YeahhhhLi commented Apr 11, 2023

I git clone paho.mqtt.cpp v1.2.0, build example and run async_subscibe, everything is ok

$ git status
HEAD detached at v1.2.0

$ ./src/samples/async_subscribe 
\Connecting to the MQTT server...
Connection success

Subscribing to topic 'hello'
	for client paho_cpp_async_subcribe using QoS1

Press Q<Enter> to quit

Subscription success for token: [1]
	token topic: 'hello', ...

And then I test the reconnect function

systemctl restart mosquitto.service 

the error happened:

Connection lost
Reconnecting...
Connection attempt failed
Error: MQTT error [-18]: Connect or disconnect command ignored

Isn't it better to report errors through on_failure here?

At present, when I introduce the reconnection function, I must use try catch to catch the exception.

So, is there a better solution?

Similar problems also occur in the async client publish interface:

    paho_mqtt::message_ptr message = paho_mqtt::make_message(topic, data, size);
    client_->publish(message, /*user context*/nullptr, *iaction_cb_);

it will throw exception when client is disconneted

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