[solved] MQTT cannot connect to Mosquitto since upgrading to 1.4.7

Today I installed the new mosquitto version via apt-get and now mqtt cannot connect to the broker anymore.
Anyone experiencing the same issue?

2016-01-09 12:50:57.476 [INFO ] [.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2016-01-09 12:50:57.479 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto'
2016-01-09 12:50:57.830 [ERROR] [.io.transport.mqtt.MqttService] - Error starting broker connection
org.eclipse.paho.client.mqttv3.MqttException: Verbindung zu Server kann nicht hergestellt werden
    at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:75) ~[na:na]
    at org.eclipse.paho.client.mqttv3.internal.SSLNetworkModule.start(SSLNetworkModule.java:77) ~[na:na]
    at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:538) ~[na:na]
    at java.lang.Thread.run(Thread.java:744) ~[na:1.8.0]
Caused by: java.net.ConnectException: Verbindungsaufbau abgelehnt
    at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0]
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345) ~[na:1.8.0]
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0]
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0]
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0]
    at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0]
    at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:649) ~[na:1.8.0]
    at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:66) ~[na:na]
    ... 3 common frames omitted

Is it possible that mosquitto’s configuration was changed on upgrade? Are you sure mosquitto is still listening on the port(s) you intend?

Status of mosquitto is active and running

pi@raspberrypi2 /etc/apt/sources.list.d $ sudo service mosquitto status
● mosquitto.service - LSB: mosquitto MQTT v3.1 message broker
   Loaded: loaded (/etc/init.d/mosquitto)
   Active: active (running) since Sa 2016-01-09 13:33:55 CET; 13min ago
  Process: 1055 ExecStart=/etc/init.d/mosquitto start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/mosquitto.service
           └─1086 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

Jan 09 13:33:55 raspberrypi2 systemd[1]: Starting LSB: mosquitto MQTT v3.1 message broker...
Jan 09 13:33:55 raspberrypi2 mosquitto[1055]: Starting network daemon:: mosquitto.
Jan 09 13:33:55 raspberrypi2 systemd[1]: Started LSB: mosquitto MQTT v3.1 message broker.

and I am able to publish messages and receive messages via mosquitto_sub and _pub …

Are you explicitly passing the -h host and -p port arguments to mosquitto_sub and mosquitto_pub? If not, where are those tools getting their connection settings?

If you do netstat -an | grep LISTEN at a prompt, do you see the mosquitto server listening on the port(s) you expect?

1 Like

[quote=“watou, post:4, topic:5925, full:true”]
Are you explicitly passing the -h host and -p port arguments to mosquitto_sub and mosquitto_pub?[/quote]

Not in the first place, but now:

pi@raspberrypi2 ~ $ mosquitto_pub -h -p 1883 -t testTopic/test -m "test"

pi@raspberrypi2 ~ $ mosquitto_sub -h -p 1883 -t testTopic/#

But it doesn’t show anything while using port 8883.

pi@raspberrypi2 ~ $ netstat -an | grep LISTEN
tcp        0      0   *               LISTEN
tcp        0      0  *               LISTEN
tcp        0      0   *               LISTEN
tcp        0      0  *               LISTEN
tcp        0      0  *               LISTEN
tcp        0      0    *               LISTEN
tcp        0      0 *               LISTEN
tcp        0      0*               LISTEN
tcp        0      0   *               LISTEN
tcp6       0      0 :::57383                :::*                    LISTEN
tcp6       0      0 :::139                  :::*                    LISTEN
tcp6       0      0 :::111                  :::*                    LISTEN
tcp6       0      0 :::8080                 :::*                    LISTEN
tcp6       0      0 :::8883                 :::*                    LISTEN
tcp6       0      0 :::5555                 :::*                    LISTEN
tcp6       0      0 :::22                   :::*                    LISTEN
tcp6       0      0 :::8443                 :::*                    LISTEN
tcp6       0      0 :::445                  :::*                    LISTEN

According to my openhab.cfg mqtt should publish via TLS on localhost:8883:

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883

I have no idea why there is a 0 ip adress for port 8883 in the netstat output:

tcp 0 0* LISTEN

The above means that mosquitto is only listening on the loopback interface for connections on port 1883, while

means that any host can connect that can reach the server on any interface. If you are OK to listen for 1883 connections on any interface, you would change the line in mosquitto.conf from

listener 1883


listener 1883

and restart/reload mosquitto, and see if openHAB can connect.

Thanks for the explanation!

I changed mosquitto.conf according to your advice and get now

tcp 0 0* LISTEN

so the changes were recognized. But the problem is still the same.

BUT: in addition to my apt-get upgrade a couple of hours ago I had a power outage this morning (short in a light bulb blew the fuse) and my Pi was shut down. As we all know by now this can corrupt a complete installation :joy:
I’m thinking about restoring my two day old image backup …

Problem was solely caused by the power outage, the os was corrupted.

After restoring a backup (with mosquitto 1.4.5) everything worked fine.
Then I did again an upgrade to mosquitto 1.4.7 and still everything is working fine.

Thanks for your help.

Very strange side effect from the power outage, but good to know this sort of thing can result. Thanks for the update!