moscajs / mosca

MQTT broker as a module
mosca.io
3.2k stars 509 forks source link

TypeError: Cannot convert undefined or null to object #495

Closed kevingo closed 8 years ago

kevingo commented 8 years ago

Hi, I use a mqtt client to connect to mosca broker with the following options:

client = mqtt.connect({
    port: 1883,
    host: 'localhost',
    clean: false,
    clientId: 'client-a',
    protocolId: 'MQIsdp',
    protocolVersion: 3
});

The mosca broker will broke by the TypeError: Cannot convert undefined or null to object error message. It occurs with the code snippet var subs = Object.keys(subscriptions);

It seems that the subscriptions is null or undefined, which means that the following function in the abstract.js does not work well :

  server.restoreClientSubscriptions = function restoreClientSubscriptions(client, done) {
    that.lookupSubscriptions(client, function(err, subscriptions) {
      if (err) {
        client.connection.emit("error", err);
        return;
      }

      var subs = Object.keys(subscriptions);

      async.each(subs, function(topic, inCb) {
        client.logger.debug({ topic: topic, qos: subscriptions[topic].qos }, "restoring subscription");
        client.handleAuthorizeSubscribe(
          null, true, {
          topic: topic,
          qos: subscriptions[topic].qos
        }, inCb);
      }, function(){done(subs.length === 0 ? false : true);});
    });
  };

Is any idea ? Thanks a lot.

mcollina commented 8 years ago

Should be fixed in v1.4.1 by #494

kevingo commented 8 years ago

@mcollina Thanks.