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
860 stars 159 forks source link

connect() blocks forever if reconnect configured and there is a known unrecoverable problem connecting to the broker #496

Open climategadgets opened 3 years ago

climategadgets commented 3 years ago

Expected behavior

connect() fails even if configured to reconnect if it is determined that reconnect attempts will always fail. Case in point, attempts to connect to MQTT 3 only broker with MQTT 5 only client will never succeed and must be abandoned with a clear error message.

See also: #302

Actual behavior

connect() hangs with no indication of why.

To Reproduce

Steps

With automatic reconnect enabled,

Reproducer code

Standard connect() code from HiveMQ examples

Details

SgtSilvio commented 3 years ago

Hi @climategadgets Although you are right that we should cover the most common unrecoverable problems in the default automatic reconnect, you can currently already do this manually, for example:

Mqtt5Client.builder()
    ...
    .automaticReconnectWithDefaultConfig()
    .addDisconnectedListener(context -> {
        if (isUnrecoverable(context.getCause())) {
            context.getReconnector().reconnect(false);
        }
    })
    ...