title: Why is the MQTT connect call called repeatedly?
body: <p>The below code executes fine, however the connect call apparently is called every second, as the console fills up with the message below. In this minimal example this might not seem like a problem, but when adding more code in the connect call it is not beneficial that this is the case.</p>
  <pre><code>const mqtt = require(&quot;mqtt&quot;);
  var mqtt_client = mqtt.connect(&quot;mqtt://XXXXXXXXXX:2883&quot;, {
    clientId: &quot;trigger-broker&quot;,
    username: &quot;XXXXX&quot;,
    password: &quot;XXXXX&quot;
  });
  
  mqtt_client.on(&quot;connect&quot;, () =&gt; {
    console.log(&quot;Client connected successfully&quot;);
  });
  </code></pre>
  <p>I tried changing the qos of the client and trying out with a different instance of my broker. Also I upgraded from mqtt 4.0.1 to 4.3.7 which didn't change anything.</p>
  <p>Edit: This is the beginning of the broker code</p>
  <pre><code>  broker.on(&quot;publish&quot;, async function (packet, client) {
      if (packet.payload) {
        let payload = packet.payload.toString();
        let topic = &quot;&quot;;
  
        try {
          payload = JSON.parse(payload);
          topic = packet.topic;
        } catch (e) {
          console.error(&quot;Error parsing payload&quot;, e);
          return;
        }
  </code></pre>