mosquitto icon indicating copy to clipboard operation
mosquitto copied to clipboard

Bridge does not automatically reconnect when initial connection attempt fails

Open EpicLPer opened this issue 1 year ago • 9 comments

Heya!

I'm currently noticing a weird behavior from Mosquitto when it comes to bridging external MQTT brokers. My current config bridges HiveMQ to Home Assistant's Mosquitto Add On, I've set everything up in mosquitto.conf and once it connects it works great, however at random times it either disconnects or doesn't connect at all when restarting Mosquitto. It also doesn't seem to try to connect after it initially failed, despite setting both keepalive_interval 20 and restart_timeout 20. The log simply says Expiring client local.core-mosquitto.HiveMQ due to timeout, but never tries to reconnect to the broker again after that.

Is this expected behavior or am I onto something here? :) Thanks for the help!

Mosquitto Version: 2.0.15

EpicLPer avatar Apr 27 '23 17:04 EpicLPer

Are there any updates on this?

EpicLPer avatar May 11 '23 16:05 EpicLPer

Today, I noticed the same issue, also with HiveMQ. Did you manage to fix this @EpicLPer?

fbooij avatar Jun 29 '23 21:06 fbooij

Today, I noticed the same issue, also with HiveMQ. Did you manage to fix this @EpicLPer?

Sadly so far no permanent fix, tho if I ever have an extended period of time I'll switch to a better MQTT server due to this... not sure what I'll choose yet but the lack of updates makes this annoying tbh.

EpicLPer avatar Jun 30 '23 02:06 EpicLPer

I've made an automation that monitors the value of "$SYS/broker/connection/core-mosquitto.hivemq/state" and restarts the core-mosquitto addon until it returns 1. An ugly workaround but it works.

fbooij avatar Jul 01 '23 15:07 fbooij

Hi, Not sure if it's the same regression but I was trying to set my broker to act as a bridge in a way that if external broker isn't available still be able to handle local messages and try to reconnect every once in a while. And it fails like this:

Oct 03 08:25:34 NanoPi-NEO mosquitto[31381]: mosquitto: /build/mosquitto-iuNSqR/mosquitto-1.6.9/src/loop.c:730: loop_handle_reads_writes: Assertion `pollfds[context->pollfd_index].fd == context->sock' failed.
Oct 03 08:25:34 NanoPi-NEO systemd[1]: mosquitto.service: Main process exited, code=killed, status=6/ABRT
Oct 03 08:25:34 NanoPi-NEO systemd[1]: mosquitto.service: Failed with result 'signal'.
Oct 03 08:25:34 NanoPi-NEO systemd[1]: mosquitto.service: Scheduled restart job, restart counter is at 30.
Oct 03 08:25:34 NanoPi-NEO systemd[1]: Stopped Mosquitto MQTT v3.1/v3.1.1 Broker.

But I've got ver 1.6.9. Is it even possible to set it like I want to? Maybe you can suggest another version to try?

Edit: Never mind, updating to 2.0.18 fixed the issue.

ddokupil avatar Oct 03 '23 09:10 ddokupil

I can confirm that version 2.0.18 solved these kind of problems for me.

This was under Gentoo Linux where Mosquitto version 2.0.18 currently (Nov. 2023) is considered Test, indicated as ~2.0.18.

StafrGotar avatar Nov 13 '23 15:11 StafrGotar

2.0.18 appears to solve it for me as well.

vomov avatar Nov 20 '23 14:11 vomov

I get that under 2.0.18:

1714301814: Connecting bridge (step 2) dc1-mq (dc1-mq.example.com:1883)
1714301890: Outgoing messages are being dropped for client d2-core-mq1.dc1-mq.
1715431691: Expiring client local.d2-core-mq2.dc1-mq due to timeout.

config:

connection dc1-mq
address dc1-mq.example.com:1883 
bridge_protocol_version mqttv311
round_robin false

topic # both 1

remote_username bridge-user
remote_password pass

XANi avatar May 13 '24 09:05 XANi

I'm noticing that my 2.0.18 doesn't seem to reconnect as well. Are people using specific config settings to get this to work?

doubleopinter avatar Jul 15 '24 23:07 doubleopinter