moscajs / mosca

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

Mosca crashes when publishing Message with retain-option from MQTT.js #412

Closed boristian closed 8 years ago

boristian commented 8 years ago

Hi,

since homebrew updated node to v5.6.0 this morning, mosca 1.0.2 crashes when publishing a message from a script using MQTT.js with {retain: true}.

The error is:

buffer.js:229
      throw new TypeError('list argument must be an Array of Buffers');
      ^

TypeError: list argument must be an Array of Buffers
    at Function.Buffer.concat (buffer.js:229:13)
    at BufferList.copy 

After getting this error when running my app, i've made a small test script:

const mqtt = require('mqtt')
const client = mqtt.connect()

client.on('connect', () => {
  client.subscribe('abc/+')
  client.publish('abc/a', `abc`, {retain: true})
})

client.on('message', (topic, payload) => {
  console.log(topic, payload)
})

This gives me the same error. I've cross-checked with mosquitto 1.4.7., which works. So i think it might be a mosca problem. Any suggestions?

Greetz

mcollina commented 8 years ago

What is your mosca config?

psorowka commented 8 years ago

I can confirm that, mosca tests are not running on node 5.6, but they are running fine on node 5.5.

The first failing test is

  1) mosca.persistence.LevelUp retained messages should store retain messages:
     TypeError: list argument must be an Array of Buffers
      at Function.Buffer.concat (buffer.js:229:13)
      at BufferList.copy (node_modules/msgpack5/node_modules/bl/bl.js:118:21)
      at BufferList.slice (node_modules/msgpack5/node_modules/bl/bl.js:93:15)
      at Object.encode (node_modules/msgpack5/lib/encoder.js:139:18)
      at Object.defaults.valueEncoding.encode (lib/persistence/levelup.js:39:22)
      at Object.encodeValue (node_modules/level-sublevel/node_modules/levelup/lib/codec.js:37:39)
      at node_modules/level-sublevel/nut.js:92:25
      at Array.map (native)
      at Object.apply (node_modules/level-sublevel/nut.js:87:15)
      at EventEmitter.emitter.put (node_modules/level-sublevel/shell.js:49:9)
      at LevelUpPersistence.storeRetained (lib/persistence/levelup.js:126:20)
      at Context.<anonymous> (test/persistence/abstract.js:53:21)

I suggest we make a "quick fix" by adding engine "< 5.6" to package.json. Or do you have time to fix that soon @mcollina? I don't :(

boristian commented 8 years ago

The config is pretty standard, i use mosca as a standalone service for dev with websocket enabled:

mosca -v --http-port 3001 --http-bundle --http-static ./ | bunyan
mcollina commented 8 years ago

This is a problem on bl https://github.com/rvagg/bl/issues/26 introduced by https://github.com/nodejs/node/pull/4951.

mcollina commented 8 years ago

This is solved and released by https://github.com/rvagg/bl/pull/27