iotagent-ul icon indicating copy to clipboard operation
iotagent-ul copied to clipboard

iotagent-ul does not reconnect to mqtt broker in case of failed connection

Open chicco785 opened this issue 6 years ago • 12 comments

when the mqtt broker stops or there are connectivity issues, the agent does not recover the connection correctly.

chicco785 avatar Mar 22 '18 10:03 chicco785

Eevn i am facing the same issue.... Plz help me

Ashokkurukundi avatar Dec 13 '18 06:12 Ashokkurukundi

Same problem. We are using iotagent 1.8.0 with docker.

tadeo-n avatar May 04 '20 13:05 tadeo-n

Could you try with latest version please?

AlvaroVega avatar May 04 '20 13:05 AlvaroVega

With the latest version (1.13.0) the problem has been solved. Thank you

tadeo-n avatar May 05 '20 14:05 tadeo-n

@tadeo-n thanks for the positive feedback report! Maybe the issue should be closed. What do you think @chicco785 @Ashokkurukundi ?

fgalan avatar May 05 '20 14:05 fgalan

I update the status. Seems with 1.13.0 the problem is less frequent, but still occurs. When MQTT is restarted sometimes IoTAgent does not reconnect to MQTT Broker.

tadeo-n avatar Jul 06 '20 07:07 tadeo-n

When MQTT is restarted sometimes IoTAgent does not reconnect to MQTT Broker.

Under which circustances that occurs? Fully randomly? Or is the some pattern?

Note that is the problem cannot be reproduced it is extremely hard to debug and solve...

fgalan avatar Jul 06 '20 09:07 fgalan

For now we haven´t found any pattern.

The metrics reach MQTT but IoTAgent is not connecting to it, I don't see any errors on IoTAgent. MQTT is restarted but IoTAgent does not attempt reconnection.

IoTAgent restarts and the problem is solved.

We have updated the version of the MQTT Broker (we are using the eclipse-mosquitto image) to see if it fixes it (I don't think so) .

tadeo-n avatar Jul 06 '20 09:07 tadeo-n

I was trying to reproduce your issue. Starting with iotagent ul and iotagent json and mosquitto running then I've stop mosquitto:

iot-iota-json               | time=2020-07-08T08:18:45.866Z | lvl=WARN | corr=829bb753-7ca2-419a-8b39-504c472efb15 | trans=829bb753-7ca2-419a-8b39-504c472efb15 | op=IOTAJSON.MQTT.Binding | srv=n/a | subsrv=n/a | msg=reconnecting... | comp=IoTAgent
iot-iota-ul                 | time=2020-07-08T08:18:45.867Z | lvl=WARN | corr=501d9147-513c-44e2-aaea-46794099586d | trans=501d9147-513c-44e2-aaea-46794099586d | op=IOTAUL.MQTT.Binding | srv=n/a | subsrv=n/a | msg=reconnecting... | comp=IoTAgent
iot-mosquitto exited with code 137

And then I've start mosquitto again:

iot-iota-ul                 | time=2020-07-08T08:18:50.868Z | lvl=INFO | corr=501d9147-513c-44e2-aaea-46794099586d | trans=501d9147-513c-44e2-aaea-46794099586d | op=IOTAUL.MQTT.Binding | srv=n/a | subsrv=n/a | msg=creating connection | comp=IoTAgent
iot-iota-json               | time=2020-07-08T08:18:50.868Z | lvl=INFO | corr=829bb753-7ca2-419a-8b39-504c472efb15 | trans=829bb753-7ca2-419a-8b39-504c472efb15 | op=IOTAJSON.MQTT.Binding | srv=n/a | subsrv=n/a | msg=creating connection | comp=IoTAgent
iot-iota-json               | time=2020-07-08T08:18:50.873Z | lvl=INFO | corr=829bb753-7ca2-419a-8b39-504c472efb15 | trans=829bb753-7ca2-419a-8b39-504c472efb15 | op=IOTAJSON.MQTT.Binding | srv=n/a | subsrv=n/a | msg=connected | comp=IoTAgent
iot-iota-ul                 | time=2020-07-08T08:18:50.873Z | lvl=INFO | corr=501d9147-513c-44e2-aaea-46794099586d | trans=501d9147-513c-44e2-aaea-46794099586d | op=IOTAUL.MQTT.Binding | srv=n/a | subsrv=n/a | msg=connected | comp=IoTAgent
iot-mosquitto               | 2020-07-08T08:18:53: New connection from 172.17.0.17 on port 1883.
iot-mosquitto               | 2020-07-08T08:18:53: New connection from 172.17.0.16 on port 1883.
iot-mosquitto               | 2020-07-08T08:18:53: New client connected from 172.17.0.17 as mqttjs_6ceff15e (p2, c1, k0, u'iota').
iot-mosquitto               | 2020-07-08T08:18:53: New client connected from 172.17.0.16 as mqttjs_bbd1acb7 (p2, c1, k0, u'iota').
iot-iota-json               | time=2020-07-08T08:18:53.920Z | lvl=INFO | corr=829bb753-7ca2-419a-8b39-504c472efb15 | trans=829bb753-7ca2-419a-8b39-504c472efb15 | op=IOTAJSON.MQTT.Binding | srv=n/a | subsrv=n/a | msg=MQTT Client connected | comp=IoTAgent
iot-iota-ul                 | time=2020-07-08T08:18:53.920Z | lvl=INFO | corr=501d9147-513c-44e2-aaea-46794099586d | trans=501d9147-513c-44e2-aaea-46794099586d | op=IOTAUL.MQTT.Binding | srv=n/a | subsrv=n/a | msg=MQTT Client connected | comp=IoTAgent
iot-iota-ul                 | time=2020-07-08T08:18:53.921Z | lvl=DEBUG | corr=501d9147-513c-44e2-aaea-46794099586d | trans=501d9147-513c-44e2-aaea-46794099586d | op=IOTAUL.MQTT.Binding | srv=n/a | subsrv=n/a | msg=Recreating global subscriptions | comp=IoTAgent
iot-iota-json               | time=2020-07-08T08:18:53.920Z | lvl=DEBUG | corr=829bb753-7ca2-419a-8b39-504c472efb15 | trans=829bb753-7ca2-419a-8b39-504c472efb15 | op=IOTAJSON.MQTT.Binding | srv=n/a | subsrv=n/a | msg=Recreating subscriptions for all devices | comp=IoTAgent
iot-iota-ul                 | time=2020-07-08T08:18:53.921Z | lvl=DEBUG | corr=501d9147-513c-44e2-aaea-46794099586d | trans=501d9147-513c-44e2-aaea-46794099586d | op=IOTAUL.MQTT.Binding | srv=n/a | subsrv=n/a | msg=Generating topics | comp=IoTAgent
iot-iota-json               | time=2020-07-08T08:18:53.921Z | lvl=DEBUG | corr=829bb753-7ca2-419a-8b39-504c472efb15 | trans=829bb753-7ca2-419a-8b39-504c472efb15 | op=IOTAJSON.MQTT.Binding | srv=n/a | subsrv=n/a | msg=Generating topics | comp=IoTAgent
iot-iota-ul                 | time=2020-07-08T08:18:53.921Z | lvl=DEBUG | corr=501d9147-513c-44e2-aaea-46794099586d | trans=501d9147-513c-44e2-aaea-46794099586d | op=IoTAgentNGSI.MongoDBGroupRegister | srv=n/a | subsrv=n/a | msg=Subscribing to topics: ["$share/ul//+/+/attrs/+","$share/ul//ul/+/+/attrs/+","$share/ul//+/+/attrs","$share/ul//ul/+/+/attrs","$share/ul//+/+/configuration/commands","$share/ul//ul/+/+/configuration/commands","$share/ul//+/+/cmdexe","$share/ul//ul/+/+/cmdexe","$share/ul/+/+/attrs/+","$share/ul/ul/+/+/attrs/+","$share/ul/+/+/attrs","$share/ul/ul/+/+/attrs","$share/ul/+/+/configuration/commands","$share/ul/ul/+/+/configuration/commands","$share/ul/+/+/cmdexe","$share/ul/ul/+/+/cmdexe"] | comp=IoTAgent
iot-iota-json               | time=2020-07-08T08:18:53.922Z | lvl=DEBUG | corr=829bb753-7ca2-419a-8b39-504c472efb15 | trans=829bb753-7ca2-419a-8b39-504c472efb15 | op=IOTAJSON.MQTT.Binding | srv=n/a | subsrv=n/a | msg=Subscribing to topics: ["$share/json//+/+/attrs/+","$share/json//json/+/+/attrs/+","$share/json//+/+/attrs","$share/json//json/+/+/attrs","$share/json//+/+/configuration/commands","$share/json//json/+/+/configuration/commands","$share/json//+/+/cmdexe","$share/json//json/+/+/cmdexe","$share/json//+/+/attrs/+","$share/json/json/+/+/attrs/+","$share/json//+/+/attrs","$share/json/json/+/+/attrs","$share/json//+/+/configuration/commands","$share/json/json/+/+/configuration/commands","$share/json//+/+/cmdexe","$share/json/json/+/+/cmdexe"] | comp=IoTAgent
iot-iota-ul                 | time=2020-07-08T08:18:53.927Z | lvl=DEBUG | corr=501d9147-513c-44e2-aaea-46794099586d | trans=501d9147-513c-44e2-aaea-46794099586d | op=IoTAgentNGSI.MongoDBGroupRegister | srv=n/a | subsrv=n/a | msg=Successfully subscribed to the following topics:
iot-iota-ul                 | ["$share/ul//+/+/attrs/+","$share/ul//ul/+/+/attrs/+","$share/ul//+/+/attrs","$share/ul//ul/+/+/attrs","$share/ul//+/+/configuration/commands","$share/ul//ul/+/+/configuration/commands","$share/ul//+/+/cmdexe","$share/ul//ul/+/+/cmdexe","$share/ul/+/+/attrs/+","$share/ul/ul/+/+/attrs/+","$share/ul/+/+/attrs","$share/ul/ul/+/+/attrs","$share/ul/+/+/configuration/commands","$share/ul/ul/+/+/configuration/commands","$share/ul/+/+/cmdexe","$share/ul/ul/+/+/cmdexe"]
iot-iota-ul                 |  | comp=IoTAgent
iot-iota-json               | time=2020-07-08T08:18:53.928Z | lvl=DEBUG | corr=829bb753-7ca2-419a-8b39-504c472efb15 | trans=829bb753-7ca2-419a-8b39-504c472efb15 | op=IOTAJSON.MQTT.Binding | srv=n/a | subsrv=n/a | msg=Successfully subscribed to the following topics:
iot-iota-json               | ["$share/json//+/+/attrs/+","$share/json//json/+/+/attrs/+","$share/json//+/+/attrs","$share/json//json/+/+/attrs","$share/json//+/+/configuration/commands","$share/json//json/+/+/configuration/commands","$share/json//+/+/cmdexe","$share/json//json/+/+/cmdexe","$share/json//+/+/attrs/+","$share/json/json/+/+/attrs/+","$share/json//+/+/attrs","$share/json/json/+/+/attrs","$share/json//+/+/configuration/commands","$share/json/json/+/+/configuration/commands","$share/json//+/+/cmdexe","$share/json/json/+/+/cmdexe"]
iot-iota-json               |  | comp=IoTAgent
iot-mosquitto               | 2020-07-08T08:18:54: New connection from 172.17.0.16 on port 1883.
iot-mosquitto               | 2020-07-08T08:18:54: New connection from 172.17.0.17 on port 1883.
iot-mosquitto               | 2020-07-08T08:18:54: New client connected from 172.17.0.16 as mqttjs_52622ac2 (p2, c1, k0, u'iota').
iot-mosquitto               | 2020-07-08T08:18:54: New client connected from 172.17.0.17 as mqttjs_6676d5aa (p2, c1, k0, u'iota').
iot-iota-ul                 | time=2020-07-08T08:18:54.082Z | lvl=INFO | corr=501d9147-513c-44e2-aaea-46794099586d | trans=501d9147-513c-44e2-aaea-46794099586d | op=IOTAUL.MQTT.Binding | srv=n/a | subsrv=n/a | msg=MQTT Client connected | comp=IoTAgent
iot-iota-ul                 | time=2020-07-08T08:18:54.082Z | lvl=DEBUG | corr=501d9147-513c-44e2-aaea-46794099586d | trans=501d9147-513c-44e2-aaea-46794099586d | op=IOTAUL.MQTT.Binding | srv=n/a | subsrv=n/a | msg=Recreating global subscriptions | comp=IoTAgent
iot-iota-ul                 | time=2020-07-08T08:18:54.083Z | lvl=DEBUG | corr=501d9147-513c-44e2-aaea-46794099586d | trans=501d9147-513c-44e2-aaea-46794099586d | op=IOTAUL.MQTT.Binding | srv=n/a | subsrv=n/a | msg=Generating topics | comp=IoTAgent
iot-iota-ul                 | time=2020-07-08T08:18:54.083Z | lvl=DEBUG | corr=501d9147-513c-44e2-aaea-46794099586d | trans=501d9147-513c-44e2-aaea-46794099586d | op=IoTAgentNGSI.MongoDBGroupRegister | srv=n/a | subsrv=n/a | msg=Subscribing to topics: ["$share/ul//+/+/attrs/+","$share/ul//ul/+/+/attrs/+","$share/ul//+/+/attrs","$share/ul//ul/+/+/attrs","$share/ul//+/+/configuration/commands","$share/ul//ul/+/+/configuration/commands","$share/ul//+/+/cmdexe","$share/ul//ul/+/+/cmdexe","$share/ul/+/+/attrs/+","$share/ul/ul/+/+/attrs/+","$share/ul/+/+/attrs","$share/ul/ul/+/+/attrs","$share/ul/+/+/configuration/commands","$share/ul/ul/+/+/configuration/commands","$share/ul/+/+/cmdexe","$share/ul/ul/+/+/cmdexe"] | comp=IoTAgent
iot-iota-json               | time=2020-07-08T08:18:54.082Z | lvl=INFO | corr=829bb753-7ca2-419a-8b39-504c472efb15 | trans=829bb753-7ca2-419a-8b39-504c472efb15 | op=IOTAJSON.MQTT.Binding | srv=n/a | subsrv=n/a | msg=MQTT Client connected | comp=IoTAgent
iot-iota-json               | time=2020-07-08T08:18:54.082Z | lvl=DEBUG | corr=829bb753-7ca2-419a-8b39-504c472efb15 | trans=829bb753-7ca2-419a-8b39-504c472efb15 | op=IOTAJSON.MQTT.Binding | srv=n/a | subsrv=n/a | msg=Recreating subscriptions for all devices | comp=IoTAgent
iot-iota-ul                 | time=2020-07-08T08:18:54.084Z | lvl=DEBUG | corr=501d9147-513c-44e2-aaea-46794099586d | trans=501d9147-513c-44e2-aaea-46794099586d | op=IoTAgentNGSI.MongoDBGroupRegister | srv=n/a | subsrv=n/a | msg=Successfully subscribed to the following topics:
iot-iota-ul                 | ["$share/ul//+/+/attrs/+","$share/ul//ul/+/+/attrs/+","$share/ul//+/+/attrs","$share/ul//ul/+/+/attrs","$share/ul//+/+/configuration/commands","$share/ul//ul/+/+/configuration/commands","$share/ul//+/+/cmdexe","$share/ul//ul/+/+/cmdexe","$share/ul/+/+/attrs/+","$share/ul/ul/+/+/attrs/+","$share/ul/+/+/attrs","$share/ul/ul/+/+/attrs","$share/ul/+/+/configuration/commands","$share/ul/ul/+/+/configuration/commands","$share/ul/+/+/cmdexe","$share/ul/ul/+/+/cmdexe"]
iot-iota-ul                 |  | comp=IoTAgent
iot-iota-json               | time=2020-07-08T08:18:54.083Z | lvl=DEBUG | corr=829bb753-7ca2-419a-8b39-504c472efb15 | trans=829bb753-7ca2-419a-8b39-504c472efb15 | op=IOTAJSON.MQTT.Binding | srv=n/a | subsrv=n/a | msg=Generating topics | comp=IoTAgent
iot-iota-json               | time=2020-07-08T08:18:54.083Z | lvl=DEBUG | corr=829bb753-7ca2-419a-8b39-504c472efb15 | trans=829bb753-7ca2-419a-8b39-504c472efb15 | op=IOTAJSON.MQTT.Binding | srv=n/a | subsrv=n/a | msg=Subscribing to topics: ["$share/json//+/+/attrs/+","$share/json//json/+/+/attrs/+","$share/json//+/+/attrs","$share/json//json/+/+/attrs","$share/json//+/+/configuration/commands","$share/json//json/+/+/configuration/commands","$share/json//+/+/cmdexe","$share/json//json/+/+/cmdexe","$share/json//+/+/attrs/+","$share/json/json/+/+/attrs/+","$share/json//+/+/attrs","$share/json/json/+/+/attrs","$share/json//+/+/configuration/commands","$share/json/json/+/+/configuration/commands","$share/json//+/+/cmdexe","$share/json/json/+/+/cmdexe"] | comp=IoTAgent
iot-iota-json               | time=2020-07-08T08:18:54.084Z | lvl=DEBUG | corr=829bb753-7ca2-419a-8b39-504c472efb15 | trans=829bb753-7ca2-419a-8b39-504c472efb15 | op=IOTAJSON.MQTT.Binding | srv=n/a | subsrv=n/a | msg=Successfully subscribed to the following topics:
iot-iota-json               | ["$share/json//+/+/attrs/+","$share/json//json/+/+/attrs/+","$share/json//+/+/attrs","$share/json//json/+/+/attrs","$share/json//+/+/configuration/commands","$share/json//json/+/+/configuration/commands","$share/json//+/+/cmdexe","$share/json//json/+/+/cmdexe","$share/json//+/+/attrs/+","$share/json/json/+/+/attrs/+","$share/json//+/+/attrs","$share/json/json/+/+/attrs","$share/json//+/+/configuration/commands","$share/json/json/+/+/configuration/commands","$share/json//+/+/cmdexe","$share/json/json/+/+/cmdexe"]
iot-iota-json               |  | comp=IoTAgent

AlvaroVega avatar Jul 08 '20 08:07 AlvaroVega

Are you using any of these options? https://github.com/telefonicaid/iotagent-json/blob/master/docs/installationguide.md#mqtt-configuration https://github.com/telefonicaid/iotagent-ul/blob/master/docs/installationguide.md#mqtt-binding-configuration

retries: Number of MQTT connection error retries (default is 5). retryTime: Time between MQTT connection retries (default is 5 seconds).

AlvaroVega avatar Jul 08 '20 08:07 AlvaroVega

Thanks Alvaro. Now we are using this parameters:

      - "IOTA_MQTT_RETRIES=200"
      - "IOTA_MQTT_RETRY_TIME=10"

Seems it's working on test environment. Let us try for a while in production. I answer when I have verified.

tadeo-n avatar Jul 08 '20 10:07 tadeo-n

Hi tadeo-n

Can we know is it stabilized and fixed? any observations such that we can take it up for our deployment as well.

onrao avatar Apr 08 '22 14:04 onrao