eclipse / paho.mqtt.rust

paho.mqtt.rust
Other
527 stars 102 forks source link

Force AsyncClient to cancel a connect attempt so that it can be dropped #180

Closed tross-skybell closed 1 year ago

tross-skybell commented 1 year ago

I timeout waiting to connect but I cannot exit the function until the connect times out and I don't seem to be able to control that timeout.

` let conn_opts = mqtt::ConnectOptionsBuilder::new() .ssl_options(ssl_opts) .connect_timeout(time::Duration::from_millis(5000)) .keep_alive_interval(time::Duration::from_secs(30)) .automatic_reconnect(time::Duration::from_millis(500), time::Duration::from_secs(30)) .clean_session(true) .clean_start(false) .finalize();

let result = mqtt_client.connect(conn_opts).wait_for(time::Duration::frommillis(5000)); match result { Ok() => { }, Err(e) => { //log_Info!(log::Module::Cloud, "Dropping mqtt_client"); drop(mqtt_client); //log_Info!(log::Module::Cloud, "Continue now"); continue 'aws_main; }, }
`

In the above example (in the case of failure to connect) there are 60 seconds between the drop and continue. I assume that is because the connection is still waiting to time out, but the timeout should just be 5 seconds. I can't seem to find any other timers that would cause this issue.

Is there something obvious I am missing?

tross-skybell commented 1 year ago

The 60 seconds appears to be something on the system itself (still debugging). So let me re-phrase the question a bit.

Is there any way that I force mqtt_client to abort a connection? Disconnect doesn't work (since it isn't actually connected).

tross-skybell commented 1 year ago

Update. I found the source of the problem on my system. The random seed wasn't yet initialized at boot so any openssl call hangs until it can get a random number.

This probably means that there isn't anything paho mqtt can do since it is stuck pending.

fpagliughi commented 1 year ago

I think you're right that this can't really be fixed easily if it's in a system call.