stompgem / stomp

A ruby gem for sending and receiving messages from a Stomp protocol compliant message queue. Includes: failover logic, ssl support.
http://stomp.github.com
Apache License 2.0
152 stars 80 forks source link

Publish with wrong credentials causes IRB to crash #103

Closed jdlourenco closed 10 years ago

jdlourenco commented 10 years ago

When connecting to a RabbitmMQ broker (with the STOMP adapter enabled) with wrong credentials and trying to publish a message to a topic IRB crashes.

Here's what I am doing

require 'stomp'
rmq = Stomp::Client.open 'user', 'pass', 'localhost', 61613 # wrong credentials
rmq.publish("/topic/test", "ol")

And this is what I get:

2.1.2 :005 > /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/input-method.rb:152:in `readline': Illegal command (Stomp::Error::BrokerException)
        from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/input-method.rb:152:in `gets'
        from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:472:in `block (2 levels) in eval_input'
        from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:624:in `signal_status'
        from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:471:in `block in eval_input'
        from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/ruby-lex.rb:190:in `call'
        from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/ruby-lex.rb:190:in `buf_input'
        from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/ruby-lex.rb:105:in `getc'
        from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/slex.rb:206:in `match_io'
        from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/slex.rb:76:in `match'
        from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/ruby-lex.rb:290:in `token'
        from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/ruby-lex.rb:266:in `lex'
        from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/ruby-lex.rb:237:in `block (2 levels) in each_top_level_statement'
        from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/ruby-lex.rb:233:in `loop'
        from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/ruby-lex.rb:233:in `block in each_top_level_statement'
        from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/ruby-lex.rb:232:in `catch'
        from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/ruby-lex.rb:232:in `each_top_level_statement'
        from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:488:in `eval_input'
        from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:397:in `block in start'
        from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:396:in `catch'
        from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:396:in `start'
        from /usr/local//rvm/rubies/ruby-2.1.2/bin/irb:11:in `<main>'

Followed by IRB crashing.

Shouldn't the Client.open call return an error when it is provided with wrong credentials in the first place?

I am using Ruby 2.1.2, stomp-1.3.2 gem and RabbitMQ 3.3.0, but I have also tested it with older ruby versions and got the same result.

gmallard commented 10 years ago

I assume you are running RMQ on 61613, correct? And that it is just the user/password that are "wrong credentials", correct?

I do not see an irb crash in your post. But the rmq.publish certainly fails. And your publish fails in the exact same way as it does here.

You are neglecting to check that open has actually succeeded.

So, .... after the Client.open, what is the output of

 p rmq.connection_frame.command

?

If it is 'ERROR', your code needs to check for open errors (from the broker). And handle them according to your needs. Something like:

require 'stomp'
rmq = Stomp::Client.open 'user', 'pass', 'localhost', 61613 # wrong credentials
if rmq.connection_frame.command == "ERROR"
    raise rmq.connection_frame.body
end
rmq.publish("/topic/test", "ol")

Please indicate if you require further assistance with this.

It is not a gem bug.

gmallard commented 10 years ago

I am closing this issue, because no further comments have been received from @jdlourenco .

Re-open this, or create a new issue if you believe a gem bug actually exists.

Thanks.