Some questions (bugs?) about closing connection

#1

Hello, guys! first of all - thank you for your awesome work on Crossbar and Autobahn :slight_smile:
I’m using Autobahn.js v0.10.1 from NPM and something strange is going on with closing WAMP connections :slight_smile: so I’d like to clarify - is it bug or it’s me doing something wrong?

  1. When I call Connection.close(‘my.close.uri’, ‘my some explayning message’) and then try to see reason and details params in Connection.onclose handler of the same connection, I see that:
  • reason = “closed” (it’s ok)
  • details.reason = “wamp.close.normal”. NOT my.close.uri, as I wanted. And also - NOT wamp.goodbye.normal, as in documentation.
  • details.message = empty string, not “my some explaining message”
  1. When I try to call Connection.open() from inside of Connection.onclose handler - I got TypeError
    W:\node_modules\autobahn\lib\connection.js:311
    self._session.join(self._options.realm, self._options.authmethods, self._options.authid);

TypeError: Cannot read property ‘join’ of null
at Object.self._transport.onopen (W:\node_modules\autobahn\lib\connection.js:311:23)
at WebSocket. (W:\node_modules\autobahn\lib\transport\websocket.js:118:23)
at emitNone (events.js:67:13)
at WebSocket.emit (events.js:166:7)
at WebSocket.establishConnection (W:\node_modules\ws\lib\WebSocket.js:887:8)
at ClientRequest.upgrade (W:\node_modules\ws\lib\WebSocket.js:778:25)
at ClientRequest.g (events.js:260:16)
at emitThree (events.js:97:13)
at ClientRequest.emit (events.js:175:7)
at Socket.socketOnData (_http_client.js:337:11)
It seems that Autobahn does not like to open next session if call of onClose handler from previous session is not finished yet. Because if, for example, I delay this open call by replacing Connection.open() with setTimeout(() => Connection.open(), 1000) - everything goes smoothly.

The sample code follows:

···

var Autobahn = require(’…/node_modules/autobahn’);

var wampSession;
var wampConnection = new Autobahn.Connection({
url: ‘ws://myhost/api’,
realm: ‘myrealm’,
use_es6_promises: false
});

wampConnection.onopen = onOpen;
wampConnection.onclose = onClose;

function onOpen(session) {
wampSession = session;
var myReason = ‘my.close.reason.uri’;
var myMessage = ‘my some explaining message’;
console.log(“Connection opened. Now let’s try to close it with reason=”, myReason, ’ and message=’, myMessage);

wampConnection.close(myReason, myMessage);
};

function onClose(reason, details) {
console.log('Connection closed, reason = ', reason, ‘, details’, JSON.stringify(details));

// retry connection, even if closed explicitly

if(reason == 'closed') {
  console.log('Connection was closed explicitly, should reconnect');
  wampConnection.open();
  //setTimeout(() => wampConnection.open(), 1000);
}

return true;
}

wampConnection.open();

``

0 Likes

#2

And my Crossbar version is 0.13.2, if it matters

0 Likes