title: libmosquitto does not properly reconnect
body: <p>I am experimenting with libmosquitto-dev on Raspbian and having some issues.</p>
  <p>My code works absolutely fine so far. I can connect to a broker and once the topic gets an update my programm prints the message as it should.
  It's just the point when the broker dies after connection and gets restarted.
  My code realize the connection dropped and tries to reconnect. Once the broker is back online my code reconnects. But from this on it does not print any updates on the channel.</p>
  <p>Why not? I thought this would catch up the connection fine, but it does not.</p>
  <p>Her's my code:</p>
  <pre><code>[...]
  static int run = 1;
  
  void connect_callback(struct mosquitto *mosq, void *obj, int result)
  {
          printf(&quot;connect callback, rc=%d\n&quot;, result);
  }
  
  void message_callback(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message)
  {
          bool match = 0;
          printf(&quot;got message '%.*s' for topic '%s'\n&quot;, message-&gt;payloadlen, (char*) message-&gt;payload, message-&gt;topic);
  
          mosquitto_topic_matches_sub(&quot;Heizung&quot;, message-&gt;topic, &amp;match);
          if (match) {
              printf(&quot;got message for HEIZUNG topic\n&quot;);
      }
  }
  
  
  int main(int argc, char *argv[])
  {
  uint8_t reconnect = true;
  char clientid[24];
  struct mosquitto *mosq;
  int rc = 0;
  
  
  mosquitto_lib_init();
  memset(clientid, 0, 24);
  snprintf(clientid, 23, &quot;mylog_%d&quot;, getpid());
  mosq = mosquitto_new(clientid, true, 0);
  
  if(mosq){
      mosquitto_connect_callback_set(mosq, connect_callback);
      mosquitto_message_callback_set(mosq, message_callback);
  
      rc = mosquitto_connect(mosq, mqtt_host, mqtt_port, 60);
      mosquitto_subscribe(mosq, NULL, &quot;Heizung&quot;, 0);
  
  //  rc = mosquitto_loop_forever(mosq,20,5); // Tried with this function but same issue.
      while(run){
          rc = mosquitto_loop(mosq, -1, 1);
          if(run &amp;&amp; rc){
              printf(&quot;connection error!\n&quot;);
              sleep(10);
              mosquitto_reconnect(mosq);
          }
      }
      mosquitto_destroy(mosq);
  }
  mosquitto_lib_cleanup();
  return rc;
  }
  </code></pre>
  <p>What I see as output is the following:</p>
  <pre><code>connect callback, rc=0
  got message 'ON1' for topic 'Heizung'
  got message for Heizung topic
  got message 'ON2' for topic 'Heizung'
  got message for Heizung topic
  got message 'ON3' for topic 'Heizung'
  got message for Heizung topic
  connection error!
  connect callback, rc=0
  </code></pre>
  <p>You see the connection error (where &quot;systemctl stop mosquitto&quot; took place). And you see reconnection appears to be successful  once the broker is back again. But it does not print any of the new messages which are send by the subscriber after the broker is back. Running the mosquitto_sub command in parallel sees all messages!</p>
  <p>Any idea what is wrong here?
  Thanks a lot!</p>
  <p>/KNEBB</p>