Git Product home page Git Product logo

Comments (10)

mcollina avatar mcollina commented on July 30, 2024

That's a fun issue, thanks for reporting! :) Not sure what's the problem, I'll have a look.
However, I don't get why this is triggered over WebSocket and not over standard TCP.
All Mosca code is the same over TCP and WebSocket, all the WS-specific code is in Mows itself.
It might be a trivial but hard to find bug, again.

Can you please post the client's log?

from mosca.

ldstein avatar ldstein commented on July 30, 2024

I'll recheck with a NodeJS client - to be honest, I spent most of my day dealing exploring the Websocket functionality of Mosca today.

Here is the browser console.log:

Connecting... index3.html:31
Published /heartbeat/1 index3.html:46
Connected index3.html:17
Published /heartbeat/2 index3.html:46
Received: /heartbeat/2 Message:  index3.html:28
Published /heartbeat/3 index3.html:46
Received: /heartbeat/3 Message:  index3.html:28
Published /heartbeat/4 index3.html:46
Received: /heartbeat/4 Message:  index3.html:28
Closed, reconnecting in 1000 index3.html:23
Published /heartbeat/5 index3.html:46
Published /heartbeat/6 index3.html:46
Published /heartbeat/7 index3.html:46
Published /heartbeat/8 index3.html:46
Closed, reconnecting in 1000 index3.html:23
Published /heartbeat/9 index3.html:46
Closed, reconnecting in 1000 index3.html:23
Published /heartbeat/10 index3.html:46
Closed, reconnecting in 1000 index3.html:23
Published /heartbeat/11 index3.html:46
Closed, reconnecting in 1000 index3.html:23
Published /heartbeat/12 index3.html:46
Closed, reconnecting in 1000 index3.html:23
Published /heartbeat/13 index3.html:46
Closed, reconnecting in 1000 index3.html:23
Closed, reconnecting in 1000 index3.html:23
Closed, reconnecting in 1000 index3.html:23
Published /heartbeat/14 index3.html:46
Published /heartbeat/15 index3.html:46
Closed, reconnecting in 1000 index3.html:23
Published /heartbeat/16 index3.html:46
Published /heartbeat/17 index3.html:46
Closed, reconnecting in 1000 index3.html:23
Published /heartbeat/18 index3.html:46
Published /heartbeat/19 index3.html:46
Closed, reconnecting in 1000 index3.html:23
Published /heartbeat/20 index3.html:46
Published /heartbeat/21 index3.html:46
Closed, reconnecting in 1000 index3.html:23
Published /heartbeat/22 index3.html:46
Published /heartbeat/23 index3.html:46
Closed, reconnecting in 10

Mosca log during same period. Started then stopped and restarted once:

C:\nodeProjects\mosca>node bin/mosca -v --port 1883 --http-port 1884 | bunyan
[2013-11-07T10:08:45.067Z]  INFO: mosca/7848 on VIP-PC-Leo: server started (port=1883, httpPort=1884)
[2013-11-07T10:08:47.999Z]  INFO: mosca/7848 on VIP-PC-Leo: client connected (client=Browser1383818926987)
[2013-11-07T10:08:48.010Z]  INFO: mosca/7848 on VIP-PC-Leo: published packet (client=Browser1383818926987)
    packet: {
      "topic": "/heartbeat/1"
    }
[2013-11-07T10:08:48.010Z]  INFO: mosca/7848 on VIP-PC-Leo: subscribed to topic(client=Browser1383818926987, topic=/heartbeat/*, qos=0)
[2013-11-07T10:08:48.991Z]  INFO: mosca/7848 on VIP-PC-Leo: delivering message (client=Browser1383818926987, topic=/heartbeat/2)
[2013-11-07T10:08:48.992Z]  INFO: mosca/7848 on VIP-PC-Leo: published packet (client=Browser1383818926987)
    packet: {
      "topic": "/heartbeat/2"
    }
[2013-11-07T10:08:49.991Z]  INFO: mosca/7848 on VIP-PC-Leo: delivering message (client=Browser1383818926987, topic=/heartbeat/3)
[2013-11-07T10:08:49.991Z]  INFO: mosca/7848 on VIP-PC-Leo: published packet (client=Browser1383818926987)
    packet: {
      "topic": "/heartbeat/3"
    }
[2013-11-07T10:08:50.992Z]  INFO: mosca/7848 on VIP-PC-Leo: delivering message (client=Browser1383818926987, topic=/heartbeat/4)
[2013-11-07T10:08:50.992Z]  INFO: mosca/7848 on VIP-PC-Leo: published packet (client=Browser1383818926987)
    packet: {
      "topic": "/heartbeat/4"
    }
Terminate batch job (Y/N)?
^C
C:\nodeProjects\mosca>node bin/mosca -v --port 1883 --http-port 1884 | bunyan[2013-11-07T10:08:52.922Z]  INFO: mosca/2332 on VIP-PC-Leo: server started (port
=1883, httpPort=1884)
[2013-11-07T10:08:54.062Z]  INFO: mosca/2332 on VIP-PC-Leo: client connected (client=Browser1383818926987)
[2013-11-07T10:08:55.074Z]  INFO: mosca/2332 on VIP-PC-Leo: closed (client=Browser1383818926987)
[2013-11-07T10:08:55.074Z]  INFO: mosca/2332 on VIP-PC-Leo: client connected (client=Browser1383818926987)
[2013-11-07T10:08:56.083Z]  INFO: mosca/2332 on VIP-PC-Leo: closed (client=Browser1383818926987)
[2013-11-07T10:08:56.083Z]  INFO: mosca/2332 on VIP-PC-Leo: client connected (client=Browser1383818926987)
[2013-11-07T10:08:57.092Z]  INFO: mosca/2332 on VIP-PC-Leo: closed (client=Browser1383818926987)
[2013-11-07T10:08:57.092Z]  INFO: mosca/2332 on VIP-PC-Leo: client connected (client=Browser1383818926987)
[2013-11-07T10:08:58.113Z]  INFO: mosca/2332 on VIP-PC-Leo: closed (client=Browser1383818926987)
[2013-11-07T10:08:58.113Z]  INFO: mosca/2332 on VIP-PC-Leo: client connected (client=Browser1383818926987)
[2013-11-07T10:08:59.119Z]  INFO: mosca/2332 on VIP-PC-Leo: closed (client=Browser1383818926987)
[2013-11-07T10:08:59.119Z]  INFO: mosca/2332 on VIP-PC-Leo: client connected (client=Browser1383818926987)
[2013-11-07T10:09:00.113Z]  INFO: mosca/2332 on VIP-PC-Leo: closed (client=Browser1383818926987)
[2013-11-07T10:09:00.113Z]  INFO: mosca/2332 on VIP-PC-Leo: client connected (client=Browser1383818926987)

from mosca.

ldstein avatar ldstein commented on July 30, 2024

It appears this issue is limited to Websocket clients.

A NodeJS client handles the Broker stopping and restarting without issue.

from mosca.

mcollina avatar mcollina commented on July 30, 2024

I can't really reproduce this on my Mac with the bundle served and built by Mosca.
What browser are you using?
Can you please try running it on Linux to check if it's a windows-only problem?

from mosca.

ldstein avatar ldstein commented on July 30, 2024

Ok, the issue appears to be specific to Windows Chrome browser.

Let me try and explain.

mqtt/lib/client.js

var MqttClient = module.exports = function MqttClient(streamBuilder, options) {
  ...
  this.on('connect', function() {
    console.warn('clientConnected'); // Tell me if_clearReconnect ever fires
    that._clearReconnect();
  });
  ...
}

MqttClient.prototype._setupStream = function(){

  ...

  this.stream.on('connect', function(){console.warn('streamConnected')}); // Tell me if stream successfully connects

  ...
}

Ok, after I restart Mosca, I see multiple 'streamConnected' and no 'clientConnected' messages appearing in Chrome's console. One of the surplus connections is then 'closed', resulting in _setupStream being run again, resulting in an infinite loop.

The loop is caused by '_clearReconnect' never fired - I suspect because the 'close' kills the prior connection's event handlers before they have a chance to fire.

The problem seems unique to Google Chrome in Windows. Firefox and IE do not exhibit the same behaviour. FF and Chromium in Ubuntu are also ok. Go figure?!

The simplest solution I've found is to force clear the reconnect loop at the beginning of _setupStream:

mqtt/lib/client.js:

MqttClient.prototype._setupStream = function() {

  this._clearReconnect();

  ...

from mosca.

mcollina avatar mcollina commented on July 30, 2024

Wooow, what a strange situation! So this is a MQTT.js bug then, I'm opening one there and release shortly.

BTW, what version of IE did you test Mosca with?

from mosca.

mcollina avatar mcollina commented on July 30, 2024

This branch should fix it: mqttjs/MQTT.js#143. Let me know if it works!

from mosca.

ldstein avatar ldstein commented on July 30, 2024

The fix appears to be working. I haven't noticed any odd behaviour over the past few days.

Regarding IE, I've been testing with v10.09200.16736. IE9 and below is throwing script errors with the browserified mows JS package.

from mosca.

mcollina avatar mcollina commented on July 30, 2024

In order to support binary data in the browser we use bops (as you figured it out), and bops relies on typed arrays.

In order to get IE9 and maybe IE8 support, you might want to try https://github.com/inexorabletash/polyfill#typed-arrays-polyfill.

I'm releasing a new version of MQTT.js soon, thanks for the check.

from mosca.

mcollina avatar mcollina commented on July 30, 2024

Released on MQTT.js v0.3.5.

from mosca.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.