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

on connection callback not triggered on reconnection to the same broker with the same mosq instance #2974

Open
anthonio9 opened this issue Jan 8, 2024 · 4 comments

Comments

@anthonio9
Copy link

anthonio9 commented Jan 8, 2024

mosquitto version: 2.0.18
system: ubuntu, kernel 5.15.0-91

Hi,

I've noticed that when running mosquitto_connect or mosquitto_connect_async on mosquitto instance that has just been disconnected from a broker, the connection callback is not triggered, even if the broker (the same broker) actually receives a connection request and reponds with a CONNACK message. This results in logs that look like below:

1704722562: New connection from 192.168.1.19:40550 on port 1883.
1704722562: New client connected from 192.168.1.19:40550 as auto-48ECE486-E347-A8CB-3E04-2E05A03E8E38 (p5, c1, k10).
1704722562: No will message specified.
1704722562: Sending CONNACK to auto-48ECE486-E347-A8CB-3E04-2E05A03E8E38 (0, 0)
1704722581: Client auto-48ECE486-E347-A8CB-3E04-2E05A03E8E38 has exceeded timeout, disconnecting.

The timeout happens because there connection callback is never triggered.

Is this the expected behavior? If yes, then it would mean that after a disconnect the mosquitto instance has to be always destroyed or reinitialized, is that the right way?

@popovec
Copy link

popovec commented Jan 8, 2024

Please try to look at the PR #2966 .. it may be the same problem.

@anthonio9
Copy link
Author

I don't think it's the same, but I'll give your branch a go anyway.
Your PR seems to take care of a situation where the client call mosquitto_connect_async before the async loop is started. In my case the async loop is started first, then the mosquitto_connect_async is run, however not always after this call the onConnectCallback is triggered, which means that not always the connection gets finalized.

@anthonio9
Copy link
Author

Should a new connection be made with a fresh mosq structure, or can it be recycled? Does it have to be recycled with mosquitto_reinitialized?

@anthonio9
Copy link
Author

Using mosquitto_reinitialized just before running the mosquitto_connect_async really helped making a reliable connection every time.

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

No branches or pull requests

2 participants