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

No support of providing exceptions while using Mqtt5AsyncClient #566

Open
amitjoy opened this issue Mar 17, 2023 · 3 comments
Open

No support of providing exceptions while using Mqtt5AsyncClient #566

amitjoy opened this issue Mar 17, 2023 · 3 comments
Labels

Comments

@amitjoy
Copy link

amitjoy commented Mar 17, 2023

Currently, the Mqtt5AsyncClient doesn't propagate the exceptions that might have been caused while connecting to the broker, for example, due to unreachable broker, wrong password etc.

The RX Client callback doOnError or the CompletableFuture callback exceptionally(..) is never executed in such scenarios.

@amitjoy amitjoy added the bug label Mar 17, 2023
@amitjoy
Copy link
Author

amitjoy commented Mar 17, 2023

This is where it should have been passed onto the callbacks.

@dominicwenig-hmq
Copy link

Thanks for reaching out.
In order to be able to do a deeper analysis, can you please share any kind of reproducer code with us?

At a first glance, it looks like the async programming might not be correct. You might not synchronize threads within your application. For example, this connect method has a blocking signature (e.g. no return future) but not blocking for the connect operation of the client.

So most likely this is where the issue happens. And there might be two options:

  1. switch the whole client code to the blocking API
  2. introduce a join() after the call to whenComplete().

@amitjoy
Copy link
Author

amitjoy commented Mar 21, 2023

The connect method is synchronous and it is expected. it simply executes the async client which doesn't block at all. This works as expected too. The async operation of the client registers callbacks internally and pass the information downstream. Calling join might fix the issue but it would block which I wouldn't want.

I would like to share with you the background of it. I wanted to introduce a new callback to understand about a situation when the OSGi messaging adapter (the source code link you already have) encounters issues to connect to the broker due to issues like invalid password, broker unreachable, protocol error etc. That's why, I wanted to introduce a new API for other consumers to implement. For this, I wanted to handle the exceptional information which is passed to the CompletableFuture callback and it never gets triggered even though the broker was unreachable.

That's why, I open this issue. FYI I found a better way to implement the aforementioned functionality by implementing MqttClientDisconnectedListener and this gets triggered always with the proper information of why the client cannot connect to the broker or if something went wrong in between. This works like a charm though.

But, I still cannot get the exceptionally() invoked when the exception occurs. Even though I don't need it now as it works perfectly because of the MqttClientDisconnectedListener, I will still try to write a reproducer code soon to verify it.

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

2 participants