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

I am getting COMMAND_INVALID - second 'channel.open' seen errors #44

Closed
wolfeidau opened this issue Jun 22, 2013 · 4 comments
Closed

I am getting COMMAND_INVALID - second 'channel.open' seen errors #44

wolfeidau opened this issue Jun 22, 2013 · 4 comments

Comments

@wolfeidau
Copy link
Contributor

Gday

Been working with rabbit.js quite a bit and started getting these errors on 0.10.12.

     Uncaught Error: COMMAND_INVALID - second 'channel.open' seen
      at Connection._onMethod (/Users/markw/Code/Javascript/testproj/node_modules/rabbit.js/node_modules/amqp/amqp.js:1155:15)
      at AMQPParser.parser.onMethod (/Users/markw/Code/Javascript/testproj/node_modules/rabbit.js/node_modules/amqp/amqp.js:897:12)
      at AMQPParser._parseMethodFrame (/Users/markw/Code/Javascript/testproj/node_modules/rabbit.js/node_modules/amqp/amqp.js:451:10)
      at frameEnd (/Users/markw/Code/Javascript/testproj/node_modules/rabbit.js/node_modules/amqp/amqp.js:192:16)
      at frame (/Users/markw/Code/Javascript/testproj/node_modules/rabbit.js/node_modules/amqp/amqp.js:177:14)
      at AMQPParser.header [as parse] (/Users/markw/Code/Javascript/testproj/node_modules/rabbit.js/node_modules/amqp/amqp.js:163:14)
      at AMQPParser.execute (/Users/markw/Code/Javascript/testproj/node_modules/rabbit.js/node_modules/amqp/amqp.js:236:21)
      at Connection.<anonymous> (/Users/markw/Code/Javascript/testproj/node_modules/rabbit.js/node_modules/amqp/amqp.js:935:14)
      at Connection.EventEmitter.emit (events.js:95:17)
      at Connection.<anonymous> (_stream_readable.js:736:14)
      at Connection.EventEmitter.emit (events.js:92:17)
      at emitReadable_ (_stream_readable.js:408:10)
      at emitReadable (_stream_readable.js:404:5)
      at readableAddChunk (_stream_readable.js:165:9)
      at Connection.Readable.push (_stream_readable.js:127:10)
      at TCP.onread (net.js:526:21)

I saw there were some issues a ways back and wonder if you had any ideas.

I have this thing i call a bus, just hides all the messaging stuff behind a couple of simple functions.

var log = require('debug')('libs:bus');
var rabbit = require('rabbit.js');

var Bus = function(){
  log('connect', settings.rabbit_url);
  this.rabbitContext = rabbit.createContext(settings.rabbit_url);
}

Bus.prototype.subscribe = function(path, cb){
  log('subscribe', path)
  var subStream = this.rabbitContext.socket('SUB')
  subStream.connect(path);
  log('callback', 'invoked');
  cb(null, subStream);
}

Bus.prototype.publish = function(path, cb){
  log('publish', path)
  var pubStream = this.rabbitContext.socket('PUB')
  pubStream.connect(path);
  log('callback', 'invoked');
  cb(null, pubStream);
}

module.exports = new Bus();

And a test using mocha.

var should = require('should');
var log = require('debug')('test:bus')

var bus = require('../bus');

describe('Bus', function () {

  it('should open a publish stream', function(done){

    log('open')

    bus.publish('sometestpub', function(err, stream){
      log('stream', 'publish');
      stream.should.exist;
      stream.write("TEST TEST", 'utf8');
      done()
    })
  })

  it('should open a subscribe stream', function(done){

    log('open')

    bus.subscribe('sometestpub', function(err, stream){
      log('stream', 'subscribe');
      //err.should.not.exist;
      stream.should.exist;
      stream.pipe(process.stdout);
      done()
    })
  })
})

This works fine on 0.8.22 and fails on 0.10.12.

@squaremo
Copy link
Owner

You are right, that sounds very like the breakage due to me not using util#inherits (or the like), as reported in #35, #37 and #38, and supposedly fixed in 8b431bf and released in v0.2.1.

I'll have a closer look at your code and try it out.

Just to check:

  • are you using rabbit.js 0.2.1?
  • does it work in, e.g., Node.JS 10.3? (that's 10-series, but before the problems in those issues)

@squaremo
Copy link
Owner

I'm surprised that runs as-is, since it doesn't synchronise on the context being open (emitting 'ready').
If I stitch that in, the tests appear to run OK. That's with rabbit.js v0.2.1, and Node.JS 0.10.4 and 0.10.12.

  it('should open a publish stream', function(done){

    log('open')

    bus.rabbitContext.on('ready', function() {
      bus.publish('sometestpub', function(err, stream){
        log('stream', 'publish');
        stream.should.exist;
        stream.write("TEST TEST", 'utf8');
        done()
      })
    })
  })

@wolfeidau
Copy link
Contributor Author

This did indeed resolve my issue, that said I think the challenge here is that, and correct me if i am wrong this "ready" event is only emitted once, so I pretty much have it around the first test and then assume in the next one that the context is in a ready state. I am not entirely keen on this, but having had a look at what you have to work with I understand with this limitations.

Originally I was trying to use the connect callback, but again this only fired on the first test, so the second would time out.

Cheers for taking the time to check it over for me, your guidance is much appreciated.

@squaremo
Copy link
Owner

Events and callbacks are almost no use for synchronisation, it is true. My adjustment was pretty crude -- just enough to delay the test run, given some assumptions (specifically that the test harness serialises tests).

I am now seeing some "send 'channel.open' seen" errors, in a different scenario. So I'm not sure it's entirely down to the problems fixed already. Stay tuned ...

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