Skip to content
This repository has been archived by the owner on Feb 11, 2020. It is now read-only.

Uncaught error - 'not opened' #69

Closed
ldstein opened this issue Nov 7, 2013 · 6 comments
Closed

Uncaught error - 'not opened' #69

ldstein opened this issue Nov 7, 2013 · 6 comments

Comments

@ldstein
Copy link
Contributor

ldstein commented Nov 7, 2013

Mosca will occasionally crash with the following output:

/usr/local/lib/node_modules/mosca/node_modules/mows/node_modules/ws/lib/WebSocket.js:187
    else throw new Error('not opened');
               ^
Error: not opened
    at WebSocket.send (/usr/local/lib/node_modules/mosca/node_modules/mows/node_modules/ws/lib/WebSocket.js:187:16)
    at WebsocketStream._write (/usr/local/lib/node_modules/mosca/node_modules/mows/node_modules/websocket-stream/index.js:80:15)
    at WebsocketStream.write (/usr/local/lib/node_modules/mosca/node_modules/mows/node_modules/websocket-stream/index.js:73:10)
    at Connection.eval [as connack] (eval at <anonymous> (/usr/local/lib/node_modules/mosca/node_modules/mqtt/lib/connection.js:58:29), <anonymous>:2:126)
    at Client.completeConnection (/usr/local/lib/node_modules/mosca/lib/client.js:277:14)
    at Client.close (/usr/local/lib/node_modules/mosca/lib/client.js:477:14)
    at /usr/local/lib/node_modules/mosca/lib/client.js:286:36
    at EventEmitter.Server.authenticate (/usr/local/lib/node_modules/mosca/lib/server.js:207:3)
    at Client.handleConnect (/usr/local/lib/node_modules/mosca/lib/client.js:245:15)
    at Connection.<anonymous> (/usr/local/lib/node_modules/mosca/lib/client.js:44:10)

Thrown when Mosca attempts to send data through a previously closed web-socket.

Adding a try{}catch{} in lib/client.js @ Line 274 will keep Mosca running:

    var completeConnection = function(){

      try
      {
          logger.info("client connected");

          that.setUpTimer();

          client.connack({
              returnCode: 0
          });

          that.server.restoreClient(that);
          that.server.emit("clientConnected", that);
      }
      catch(e)
      {
          logger.warn("completeConnection error", e);
          // Additional cleanup required?
      }
    };
@mcollina
Copy link
Collaborator

mcollina commented Nov 7, 2013

The issue is really in websocket-stream because it is not passing a callback to the ws#send() method.
Look at:
https://github.com/einaros/ws/blob/master/lib/WebSocket.js#L187 and
https://github.com/maxogden/websocket-stream/blob/master/index.js#L77-L81.

Eventually, we can patch this in Mows, but I think @maxogden will accept a pull-request against websocket-stream.
The right behavior is to emit an 'error' event.

@max-mapper
Copy link

IIRC the callback to send was deprecated and that you should instead wait
for the socket to emit open before writing

On Thu, Nov 7, 2013 at 10:24 AM, Matteo Collina notifications@git.luolix.topwrote:

The issue is really in websocket-stream because it is not passing a
callback to the ws#send() method.
Look at:
https://github.com/einaros/ws/blob/master/lib/WebSocket.js#L187 and
https://github.com/maxogden/websocket-stream/blob/master/index.js#L77-L81.

Eventually, we can patch this in Mows, but I think @maxogdenhttps://github.com/maxogdenwill accept a pull-request against websocket-stream.
The right behavior is to emit an 'error' event.


Reply to this email directly or view it on GitHubhttps://github.com//issues/69#issuecomment-27951647
.

@mcollina
Copy link
Collaborator

mcollina commented Nov 7, 2013

Yes. The problem is that we are writing after it's closed :(.

I removed the callback approach and moved to checking ws.readyState.

@mcollina
Copy link
Collaborator

mcollina commented Nov 7, 2013

Reinstalling Mosca should fix this, as a new patch version of websocket-stream has been published. Can you please confirm?

@ldstein
Copy link
Contributor Author

ldstein commented Nov 8, 2013

I can happily confirm that new patch fixes the issue!

@mcollina
Copy link
Collaborator

mcollina commented Nov 8, 2013

Ok, closing!

@mcollina mcollina closed this as completed Nov 8, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants