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

connect() blocks forever if reconnect configured and broker cannot be reached #302

Closed
dowhiletrue opened this issue Jun 18, 2019 · 6 comments

Comments

@dowhiletrue
Copy link

Expected behavior

Connecting a client with reconnect configured should throw if it can't connect initially.

Actual behavior

It blocks infinitely

To Reproduce

Reproducer code

Mqtt5Client.builder().serverHost("hostWithoutRunningBroker").automaticReconnectWithDefaultConfig().toBlocking().connect(...)

Details

  • Affected HiveMQ MQTT Client version(s): 1.1.0
  • Used JVM version: 11
@SgtSilvio
Copy link
Member

This was actually intended.
We should discuss what the default behavior should be.
You can work around in the mean time:

Mqtt5Client.builder()
        ...
        .automaticReconnectWithDefaultConfig()
        .addDisconnectedListener(context -> {
            if (context.getClientConfig().getState() == MqttClientState.CONNECTING) {
                context.getReconnector().reconnect(false);
            }
        })
        ...

@dowhiletrue
Copy link
Author

Thanks for the workaround!

There are three options on top of my mind:

  • block
  • throw
  • continue and try to connect later

Which option fits best depends on the use-case. Make the behavior configurable?

@SgtSilvio SgtSilvio added this to the 1.2 milestone Aug 10, 2019
@Razikus
Copy link

Razikus commented Apr 9, 2020

Hello i just want to poke this, cause it tooks me 2 days to understand why "exceptionally" is not working

This definitely needs to be highlighted somewhere

@ravenblackdusk
Copy link

I think I might have encountered this problem. @dowhiletrue I think throwing an exception should be the default behavior as it informs the developers if their connection configuration is incorrect; I think jdbc connection pools also have such default behavior. @SgtSilvio can you please explain what happens if I use your workaround? does it attempt to reconnect automatically initially or otherwise or does it abandon reconnection and throw an exception?

@CJure
Copy link

CJure commented Mar 15, 2022

@SgtSilvio
I also had this problem: https://stackoverflow.com/questions/71467511/hivemq-mqtt-client?noredirect=1#comment126319388_71467511

Is it not possible to have automaticReconnectWithDefaultConfig() and that

.whenComplete((connAck, throwable) ->

throws error?

@pglombardo
Copy link
Contributor

Since this issue has gone stale, I've filed a feature request with summary (and current work-around) in #622. If anyone has other ideas for improvement, please add to #622.

Thanks all for pointing this out and the helpful feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants