hivemq/hivemq-mqtt-client

How to force cancel/interrupt a reconnecting state client?

bigcat26 opened this issue ยท 3 comments

Checklist

โ“ Question

How to force cancel/interrupt a reconnecting state client?

๐Ÿ“Ž Additional context

When I try to disconnect a Mqtt3RxClient that is in the DISCONNECTED_RECONNECT state, it returns a throwable with the message โ€˜com.hivemq.client.mqtt.exceptions.MqttClientStateException: MQTT client is not connected.โ€™ However, it may still successfully reconnect after a while, which is not what I want. I need to force an interruption of the reconnecting process immediately, such as by closing the underlying socket, but I did not find any API to access the underlying socket. Do you have any suggestions?

@bigcat26 How did you fix this? We are experiencing the same issue.

Would this do it or do you have to specifically interrupt a hanging socket?

.addDisconnectedListener(context -> {
    context.getReconnector()
        .reconnect(false);
})

More examples in this file.

@bigcat26 How did you fix this? We are experiencing the same issue.

I have applied the following changes in MqttDisconnectCompletable.java:

    protected void subscribeActual(final @NotNull CompletableObserver s) {
        final MqttClientConnectionConfig connectionConfig = clientConfig.getRawConnectionConfig();
        if (connectionConfig == null) {
//            EmptyDisposable.error(MqttClientStateExceptions.notConnected(), s);
            clientConfig.getRawState().set(MqttClientState.DISCONNECTED);
            clientConfig.releaseEventLoop();
            EmptyDisposable.complete(s);
            return;
        }

It seems works.