Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null exception #236

Closed
financedemo opened this issue Jan 16, 2015 · 1 comment
Closed

Null exception #236

financedemo opened this issue Jan 16, 2015 · 1 comment

Comments

@financedemo
Copy link

Hello. I'm trying 1.0.1 with a simple example

var mqtt = require('mqtt');

// Create a client connection
var client = mqtt.connect('mqtt://test.mosquitto.org');

client.on('connect', function() { // When connected

    console.log('connected');

    // subscribe to a topic
    client.subscribe('hello/world', function() {
        // when a message arrives, do something with it
        client.on('message', function(topic, message, packet) {
            console.log("Received '" + message + "' on '" + topic + "'");
        });
    });

    // publish a message to a topic
    client.publish('hello/world', 'my message', function() {
        console.log("Message is published");
        client.end(); // Close the connection when published
    });
});

and it fails with

connected
Message is published

.../node_modules/mqtt/lib/store.js:55
  packet = this._inflights[packet.messageId];
                          ^
TypeError: Cannot read property '19063' of null

FYI with 0.3.13. it works.

@mcollina
Copy link
Member

The problem is with this line:

        client.end(); // Close the connection when published

In fact, the callback is called straight-away as it is a QoS 0 message, while the subscribe is still in-flight.

1.0.1 fixed this case for the README example, but I have not thought of about this case.

Thanks for reporting, I'll get back with a fix soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants