{"id":5854,"date":"2019-12-29T22:45:03","date_gmt":"2019-12-30T03:45:03","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=5854"},"modified":"2019-12-30T00:00:18","modified_gmt":"2019-12-30T05:00:18","slug":"testing-with-mosquitto","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=5854","title":{"rendered":"Mosquitto 1.6.8 With Websockets Becomes Unresponsive"},"content":{"rendered":"<p>When I installed software on our new server, I got the &#8220;latest and greatest&#8221;. And have found that my mosquitto server hangs after about 20 minutes. No errors. Even strace doesn&#8217;t show anything beyond it not doing anything. I am able to use the command line utilities to confirm that the service isn&#8217;t there even though it <em>looks<\/em> like it is working.<\/p>\n<p>Subscribe to the subtree of a topic:<\/p>\n<pre>mosquitto_sub -h mqtt.example.com -t testtopic\/#<\/pre>\n<p>Publish a message to a topic:<\/p>\n<pre>mosquitto_pub -h mqtt.example.com -t testtopic\/data\/lisa -m \"Test4\"<\/pre>\n<p>To test WebSockets, I&#8217;ve put together a Python script that subscribes to a topic. Changing the commented lines switches between the WebSocket reverse proxy, the old and new MQTT servers via WebSockets, and the old and new MQTT servers directly in an attempt to isolate what is wrong.<\/p>\n<pre>import sys\r\nimport paho.mqtt.client as mqtt\r\n\r\ndef on_connect(mqttc, obj, flags, rc):\r\n    print(f\"rc: {str(rc)}\")\r\n\r\ndef on_message(mqttc, obj, msg):\r\n    print(f\"{datetime.datetime.now()}: {msg.topic} {str(msg.qos)} {str(msg.payload)}\")\r\n\r\ndef on_publish(mqttc, obj, mid):\r\n    print(f\"mid: {str(mid)}\")\r\n\r\ndef on_subscribe(mqttc, obj, mid, granted_qos):\r\n    print(f\"Subscribed at {datetime.datetime.now()}: {str(mid)} {str(granted_qos)}\")\r\ndef on_log(mqttc, obj, level, string):\r\n    print(string)\r\n# Client uses websockets\r\nmqttc = mqtt.Client(transport='websockets', client_id=\"ljrTestingPythonScript\", clean_session=False)\r\n# Client uses MQTT directly\r\n#mqttc = mqtt.Client(client_id=\"ljrTestingPythonScript\", clean_session=False)\r\n\r\nmqttc.username_pw_set(\"whateveruser\", \"wh@t3v3rP@s5w0rd\")\r\nmqttc.on_message = on_message\r\nmqttc.on_connect = on_connect\r\nmqttc.on_publish = on_publish\r\nmqttc.on_subscribe = on_subscribe\r\n\r\n#mqttc.connect(\"oldmosquitto.example.com\", 80, 60)\r\nmqttc.connect(\"newmosquitto.example.com\", 80, 60)\r\n#mqttc.connect(\"newmqtt.example.com\", 1883, 60)\r\n#mqttc.connect(\"newmqtt.example.com\", 9001, 60)\r\n#mqttc.connect(\"oldmqtt.example.com\", 1883, 60)\r\n#mqttc.connect(\"oldmqtt.example.com\", 9001, 60)\r\n\r\nmqttc.subscribe(\"owntracks\/#\", 0)\r\n\r\nmqttc.loop_forever()<\/pre>\n<p>None of this helped, unfortunately. The reverse proxy couldn&#8217;t communicate with the MQTT server because it was unresponsive. Attempting to communicate with the server directly fails too.<\/p>\n<p>I see a few issues in the Mosquitto repository that are similar &#8212; and the current discussion indicates that libwebsockets 3.2.0 introduced some incompatibility that they&#8217;ve addressed in Mosquitto 1.6.7 &#8230; since my problem relates to WebSockets, I wanted to try running the iteration <em>before<\/em> whatever changed.<\/p>\n<pre>git clone --branch v3.1.0 https:\/\/libwebsockets.org\/repo\/libwebsockets\r\ncd libwebsockets\r\nmkdir build\r\ncd build\r\ncmake ..\r\nmake\r\nmake install\r\n\r\ngit clone --branch v1.6.2 https:\/\/github.com\/eclipse\/mosquitto.git\r\ncd mosquitto\r\nvi config.mk # Change WITH_WEBSOCKETS:=no to :=yes\r\nmake\r\nmake install\r\n\r\nln -s \/usr\/local\/lib\/libwebsockets.so.14 \/lib64\/\r\nln -s \/usr\/local\/lib\/libmosquitto.so.1 \/usr\/lib64\/libmosquitto.so.1\r\n\r\n\/usr\/local\/sbin\/mosquitto -v -c \/etc\/mosquitto\/mosquitto.conf<\/pre>\n<p>We&#8217;ll see if this is more reliable. It&#8217;s been up for 30 minutes &#8230; which is longer than the 1.6.8 iteration managed to run.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When I installed software on our new server, I got the &#8220;latest and greatest&#8221;. And have found that my mosquitto server hangs after about 20 minutes. No errors. Even strace doesn&#8217;t show anything beyond it not doing anything. I am able to use the command line utilities to confirm that the service isn&#8217;t there even &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[189,876,187,877],"class_list":["post-5854","post","type-post","status-publish","format-standard","hentry","category-system-administration","tag-libwebsockets","tag-mosquitto","tag-mqtt","tag-websockets"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/5854","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5854"}],"version-history":[{"count":6,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/5854\/revisions"}],"predecessor-version":[{"id":5860,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/5854\/revisions\/5860"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}