hivemq / hivemq-mqtt-client

HiveMQ MQTT Client is an MQTT 5.0 and MQTT 3.1.1 compatible and feature-rich high-performance Java client library with different API flavours and backpressure support
https://hivemq.github.io/hivemq-mqtt-client/
Apache License 2.0
832 stars 153 forks source link

Async MQTT client blocks on publish if the client is disconnected and waiting between reconnect attempts #554

Closed richturner closed 4 months ago

richturner commented 1 year ago

Expected behavior

The async client (in my case Mqtt3AsyncClient) should not block when calling send no matter what the client state is; instead I would expect to get the CompletableFuture<MqttPublish>

Actual behavior

send blocks the calling thread; I guess waiting for the client to be in a connected state?

To Reproduce

  1. Create an Mqtt3AsyncClient with reconnect logic, put an invalid host value (so the client can never actually connect)
  2. Publish an MQTT message e.g.:
    client.publishWith()
            .topic(message.topic)
            .payload(messageToBytes(message.payload))
            .send()
            .whenComplete((publish, throwable) -> {
                if (throwable != null) {
                    // Failure
                    LOG.log(Level.INFO, "Failed to publish to MQTT broker '" + getClientUri() + "'", throwable);
                } else {
                    // Success
                    LOG.finer("Published message to MQTT broker '" + getClientUri() + "'");
                }
            });
  3. Notice that the call blocks on the send call with no Future ever returned

Details

pglombardo commented 1 year ago

Hi @richturner - thanks for pointing this issue out. I'll see if I can reproduce this here locally and report back soon.

pglombardo commented 1 year ago

Hi @richturner - I haven't been able to reproduce this. Could you post your client creation code (with reconnect)?

pglombardo commented 4 months ago

Since this issue has gone stale, I'll close it out but if you want to pick up on this again, let us know. We'd be happy to help out!

Mystery406 commented 2 months ago

Same problem here, have you found any solutions to this?