# Why connection failed to broker?

**URL:** https://discourse.nodered.org/t/why-connection-failed-to-broker/61739
**Category:** General
**Tags:** docker, mqtt
**Created:** [25 April 2022 03:15 UTC](https://discourse.nodered.org/t/why-connection-failed-to-broker/61739 "2022-04-25T03:15:00Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![LinuxLover9](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/linuxlover9/32/51374_2.png) [@LinuxLover9](https://discourse.nodered.org/u/LinuxLover9)
#### Post date: [25 April 2022 03:15 UTC](https://discourse.nodered.org/t/why-connection-failed-to-broker/61739/1 "2022-04-25T03:15:00Z")

</div>

I'm running a mosquitto broker and node-red as docker images and all was fine until this morning.  
I've restarted both docker container for node-red and mosquitto, then I restarted the whole server. And finally I updated node-red to the latest docker image, but all to no avail.  
I can \_pub and \_sub with the credentials of the node-red user. The broker seems fine, but it does not see any longer connection attempts from node-red?!  
I'm really at a loss what could be the issue?

```auto
node-klomp | > node-red-docker@2.2.2 start /usr/src/node-red
node-klomp | > node $NODE_OPTIONS node_modules/node-red/red.js $FLOWS "--userDir" "/data"
node-klomp | 
node-klomp | 24 Apr 22:36:25 - [info] 
node-klomp | 
node-klomp | Welcome to Node-RED
node-klomp | ===================
node-klomp | 
node-klomp | 24 Apr 22:36:25 - [info] Node-RED version: v2.2.2
node-klomp | 24 Apr 22:36:25 - [info] Node.js version: v14.18.2
node-klomp | 24 Apr 22:36:25 - [info] Linux 4.4.0-210-generic x64 LE
node-klomp | 24 Apr 22:36:25 - [info] Loading palette nodes
node-klomp | 24 Apr 22:36:25 - [debug] Module: node-red-contrib-bigtimer 2.7.5 /data/node_modules/node-red-contrib-bigtimer
node-klomp | 24 Apr 22:36:25 - [debug] Module: node-red-contrib-config 1.2.1 /data/node_modules/node-red-contrib-config
node-klomp | 24 Apr 22:36:25 - [debug] Module: node-red-contrib-telegrambot 8.10.0 /data/node_modules/node-red-contrib-telegrambot
node-klomp | 24 Apr 22:36:25 - [debug] Module: node-red-dashboard 3.1.1 /data/node_modules/node-red-dashboard
node-klomp | 24 Apr 22:36:26 - [info] Dashboard version 3.1.1 started at /ui
node-klomp | 24 Apr 22:36:26 - [info] Settings file : /data/settings.js
node-klomp | 24 Apr 22:36:26 - [info] Context store : 'default' [module=memory]
node-klomp | 24 Apr 22:36:26 - [info] User directory : /data
node-klomp | 24 Apr 22:36:26 - [warn] Projects disabled : editorTheme.projects.enabled=false
node-klomp | 24 Apr 22:36:26 - [info] Flows file : /data/flows.json
node-klomp | 24 Apr 22:36:26 - [info] Server now running at https://127.0.0.1:1880/
node-klomp | 24 Apr 22:36:26 - [debug] loaded flow revision: 058975407b276111eac9baacefc7d7c8
node-klomp | 24 Apr 22:36:26 - [debug] red/runtime/nodes/credentials.load : user provided key
node-klomp | 24 Apr 22:36:26 - [debug] red/runtime/nodes/credentials.load : keyType=user
node-klomp | 24 Apr 22:36:26 - [info] Starting flows
node-klomp | 24 Apr 22:36:26 - [debug] red/nodes/flows.start : starting flow : global
node-klomp | 24 Apr 22:36:26 - [debug] red/nodes/flows.start : starting flow : 2f499eea.89e0d2
node-klomp | 24 Apr 22:36:26 - [debug] red/nodes/flows.start : starting flow : 9eac7f36.55cd1
node-klomp | 24 Apr 22:36:26 - [debug] red/nodes/flows.start : starting flow : c666a417.dfbfd8
node-klomp | 24 Apr 22:36:26 - [debug] red/nodes/flows.start : starting flow : de4e0039.dd2ca
node-klomp | 24 Apr 22:36:26 - [debug] red/nodes/flows.start : starting flow : a78d9fa1.954e28
node-klomp | 24 Apr 22:36:26 - [debug] red/nodes/flows.start : starting flow : ed26102b.57edf
node-klomp | 24 Apr 22:36:26 - [debug] [inject:Off at 22:30] crontab = 30 22 * * *
node-klomp | 24 Apr 22:36:26 - [debug] [inject:Toggle on 08:00] crontab = 00 08 * * *
node-klomp | 24 Apr 22:36:26 - [debug] [inject:reset to auto] crontab = 01 00 * * *
node-klomp | 24 Apr 22:36:26 - [debug] [inject:At 22:00] crontab = 00 22 * * *
node-klomp | 24 Apr 22:36:26 - [debug] [inject:On at 5:20] crontab = 20 05 * * 1,2,3,4,5
node-klomp | 24 Apr 22:36:26 - [debug] [inject:Off at 7:00] crontab = 00 07 * * 1,2,3,4,5
node-klomp | 24 Apr 22:36:26 - [debug] [inject:reset to auto] crontab = 01 12 * * *
node-klomp | 24 Apr 22:36:26 - [debug] [inject:On at 6:45] crontab = 45 06 * * 1,2,3,4,5
node-klomp | 24 Apr 22:36:26 - [debug] [inject:Daily at 22:00] crontab = 00 22 * * *
node-klomp | 24 Apr 22:36:26 - [info] Started flows
node-klomp | 24 Apr 22:36:26 - [info] [mqtt-broker:mqtt] Connection failed to broker: node-red@mqtt://mqtt:51883
node-klomp | 24 Apr 22:36:41 - [info] [mqtt-broker:mqtt] Connection failed to broker: node-red@mqtt://mqtt:51883
node-klomp | 24 Apr 22:36:56 - [info] [mqtt-broker:MQTT-tls] Connection failed to broker: node-klomp@mqtts://study.klomp.ca:51883
node-klomp | 24 Apr 22:36:56 - [info] [mqtt-broker:mqtt] Connection failed to broker: node-red@mqtt://mqtt:51883
node-klomp | 24 Apr 22:37:11 - [info] [mqtt-broker:mqtt] Connection failed to broker: node-red@mqtt://mqtt:51883
node-klomp | 24 Apr 22:37:26 - [info] [mqtt-broker:mqtt] Connection failed to broker: node-red@mqtt://mqtt:51883
node-klomp | 24 Apr 22:37:41 - [info] [mqtt-broker:MQTT-tls] Connection failed to broker: node-klomp@mqtts://study.klomp.ca:51883

```

Mosquitto log:

```auto
1650807586: Received PUBLISH from node-klomp (d0, q0, r0, m0, 'jlight/set', ... (12 bytes))
1650807586: Sending PUBLISH to node-klomp (d0, q0, r0, m0, 'jlight/set', ... (12 bytes))
1650807586: Received PUBLISH from node-klomp (d0, q0, r0, m0, 'jlight/set', ... (12 bytes))
1650807586: Sending PUBLISH to node-klomp (d0, q0, r0, m0, 'jlight/set', ... (12 bytes))
1650807609: Client node-klomp disconnected: Protocol error.

```

In fact I am running two brokers, one with and one without tls. Both stopped connecting.  
The non-tls is on a different host.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [25 April 2022 03:18 UTC](https://discourse.nodered.org/t/why-connection-failed-to-broker/61739/2 "2022-04-25T03:18:58Z")

</div>

Well, having two brokers running may be a problem.

Are they both on the same port?  
If so.... I'd say that is a problem.

Moving on:

On the machine running the/a broker, can you open a CLI / TERMINAL and send/receive messages?

Because until that is proven, nothing can be said.

# P.S.

In/on the `config` nodes of the machines trying to use the MQTT:  
Have you set the correct IP address for the broker?

Take a screen shot of the MQTT CONFIG node showing the broker IP address and name.  
Paste it and that may go a long way to helping also.

---

<div class="post-metadata">

### Author: ![LinuxLover9](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/linuxlover9/32/51374_2.png) [@LinuxLover9](https://discourse.nodered.org/u/LinuxLover9)
#### Post date: [25 April 2022 03:22 UTC](https://discourse.nodered.org/t/why-connection-failed-to-broker/61739/3 "2022-04-25T03:22:50Z")

</div>

Both brokers have a different hostname/IP address, thus that does not give connection issues. Like I implied it used to run fine for weeks. Just out of the blue it broke this morning.  
And yes I can publish and subscribe to both brokers from the CLI.

---

<div class="post-metadata">

### Author: ![LinuxLover9](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/linuxlover9/32/51374_2.png) [@LinuxLover9](https://discourse.nodered.org/u/LinuxLover9)
#### Post date: [25 April 2022 03:29 UTC](https://discourse.nodered.org/t/why-connection-failed-to-broker/61739/4 "2022-04-25T03:29:43Z")

</div>

![mqtt-tls](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/4/845dc5b88f4d5cdb4f011f6892b9c19541000172.png)  
 ![mqtt-nontls](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/6/d607b38695d80fabf9e12a3a5e22f26c566a0f24.png)  
Both used to work as is shown.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [25 April 2022 03:31 UTC](https://discourse.nodered.org/t/why-connection-failed-to-broker/61739/5 "2022-04-25T03:31:51Z")

</div>

In the second picture you have:

`server` then you have `mqtt`.

I think that need to be the IP address of the machine. Not the name of _MQTT_.

And you do know the ports are `1883` not `51883`.  
Just saying. (Well, usually. Unless you have changed the port numbers in the brokers also)

---

<div class="post-metadata">

### Author: ![LinuxLover9](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/linuxlover9/32/51374_2.png) [@LinuxLover9](https://discourse.nodered.org/u/LinuxLover9)
#### Post date: [25 April 2022 03:37 UTC](https://discourse.nodered.org/t/why-connection-failed-to-broker/61739/6 "2022-04-25T03:37:04Z")

</div>

```auto
Non-authoritative answer:
Name:	mqtt.klomp.ca
Address: 192.168.0.77

Non-authoritative answer:
Name:	study.klomp.ca
Address: 192.168.0.60

```

And yes, I deliberately changed the configured ports for both.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [25 April 2022 03:38 UTC](https://discourse.nodered.org/t/why-connection-failed-to-broker/61739/7 "2022-04-25T03:38:57Z")

</div>

Sorry, I've been there many times when I type a number I put the wrong one in.  
But as it was me who typed it I can't see the mistake.

So in that bit with the names and IP.....

You didn't cover `mqtt` as an IP address.

![d607b38695d80fabf9e12a3a5e22f26c566a0f24](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/f/1f77d98ec7741d0dbe5f0a54db978490bc606078.png)

(you have LIMITED posts if you are new here so don't squander them)

Why are you using _names_ rather than IP addresses?  
And if they are `192.x.x.x`..... they are LOCAL addresses and won't be going too far out of your LAN.

---

<div class="post-metadata">

### Author: ![LinuxLover9](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/linuxlover9/32/51374_2.png) [@LinuxLover9](https://discourse.nodered.org/u/LinuxLover9)
#### Post date: [25 April 2022 03:39 UTC](https://discourse.nodered.org/t/why-connection-failed-to-broker/61739/8 "2022-04-25T03:39:32Z")

</div>

Wondering if there is at the docker level a way to trace the traffic leaving the node-red container?  
(going to sleep on that for now...)

---

<div class="post-metadata">

### Author: ![LinuxLover9](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/linuxlover9/32/51374_2.png) [@LinuxLover9](https://discourse.nodered.org/u/LinuxLover9)
#### Post date: [25 April 2022 03:47 UTC](https://discourse.nodered.org/t/why-connection-failed-to-broker/61739/9 "2022-04-25T03:47:09Z")

</div>

the default search domain is klomp.ca, thus mqtt and mqtt.klomp.ca are the same host.  
l'm using names as to more easily move work loads.

I think I really need to look at the docker plumbing, to see what's going on.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [25 April 2022 05:21 UTC](https://discourse.nodered.org/t/why-connection-failed-to-broker/61739/10 "2022-04-25T05:21:09Z")

</div>

No problems. I am at the bottom of the learning curve anyway.

But it may not hurt to do it just to make sure that the IP numbers will (or won't) make a difference.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [25 April 2022 11:41 UTC](https://discourse.nodered.org/t/why-connection-failed-to-broker/61739/11 "2022-04-25T11:41:21Z")

</div>

Unless you've opened the port, docker won't let you communicate.

When using Docker, it is best to always assume that any problem is a Docker configuration issue. Because 99% of the time, it is. That's why a lot of us don't like using Docker for something as straight-forward as Node-RED. It adds a significant layer of complexity for very little reward or purpose for most people.

Docker is certainly useful for more complex environments that someone else has kindly packaged up 🙂 I use it for several things. But Node-RED is so easy to install, upgrade and manage in any case.

If you are going to use Docker, I recommend always using Docker Compose as it is an easy way to maintain your Docker configuration.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [24 June 2022 11:41 UTC](https://discourse.nodered.org/t/why-connection-failed-to-broker/61739/12 "2022-06-24T11:41:47Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
