Antti / rust-amqp

AMQP client in pure rust. Corresponds to rabbitmq spec.
MIT License
249 stars 45 forks source link

Session::open_url returns ByteOrderError when connecting to unexisting vhost #27

Closed phsym closed 8 years ago

phsym commented 8 years ago

I'm running it against RabbitMQ, and when I try to connect to the vhost named test which does not exist, I get this ByteOrderError which is quite a confusing error.

I call

amqp::Session::open_url("amqp://guest:guest@127.0.0.1:5672/test").unwrap();

Rust output :

(...)
DEBUG:amqp::session: Sending connection.start-ok
DEBUG:amqp::channel: Sending method connection.start-ok to channel 0
DEBUG:amqp::session: Received tune request: Tune { channel_max: 0, frame_max: 131072, heartbeat: 580 }
DEBUG:amqp::session: Sending connection.tune-ok: TuneOk { channel_max: 0, frame_max: 131072, heartbeat: 0 }
DEBUG:amqp::channel: Sending method connection.tune-ok to channel 0
DEBUG:amqp::session: Sending connection.open: Open { virtual_host: "test", capabilities: "", insist: false }
DEBUG:amqp::channel: Sending method connection.open to channel 0
ERROR:amqp::session: Error in reading loop: ByteOrderError
DEBUG:amqp::session: Exiting reading loop
thread '<main>' panicked at 'called `Result::unwrap()` on an `Err` value: ByteOrderError', ../src/libcore\result.rs:741
stack backtrace:
   0:           0xabe4bc - sys::backtrace::write::hbaface7b7aca00c8D6t
   1:           0xac675e - panicking::log_panic::h27a9bd9f86275364CDy
(...)

RabbitMQ log :

=INFO REPORT==== 29-Feb-2016::23:28:32 ===
accepting AMQP connection <0.2179.0> (x.x.x.2:60017 -> x.x.x.15:5672)

=ERROR REPORT==== 29-Feb-2016::23:28:35 ===
closing AMQP connection <0.2179.0> (x.x.x.2:60017 -> x.x.x.15:5672):
{handshake_error,opening,0,
                 {amqp_error,access_refused,
                             "access to vhost 'test' refused for user 'guest'",
                             'connection.open'}}
Antti commented 8 years ago

Hi,

I'm not sure how to reproduce this. It seems that your server forcefully closes the connection (which is fine according to the AMQP protocol) rather than sending connection.close. Can you please tell me how to configure the rabbitmq server to do that. I have a fix for that, but I can't test it properly.

phsym commented 8 years ago

I run the same test using the go amqp library, and it returns the proper error code. The rabbitmq server has the default configuration from Centos7, running in a virtualbox, behind a nated network, clients run in windows 7 (hosting the virtual box).

I don't have my computer with me right now, but I'll send you my rabbit configuration file.

If you push your fix to a dedicated branch, I can tryitT.

Antti commented 8 years ago

Check this branch: https://github.com/Antti/rust-amqp/tree/check_buffer_len_before_reading_frame.

It should return protocol error at the moment, but I can probably handle it specifically in the session init to return auth error or something else.

phsym commented 8 years ago

Here is my rabbitmq config file : rabbitmq.config.txt

When I run the same test in go (with go amqp library), i get the proper 403 (access-refused) error :

panic: Cannot initialize table : Exception (403) Reason: "no access to this vhost"

Let's try you branch, I'll keep you up to date

phsym commented 8 years ago

Tried your fix and got :

ERROR:amqp::session: Error in reading loop: Protocol("Error reading frame header. Expected to read 7 bytes, but read 0")
thread '<main>' panicked at 'called `Result::unwrap()` on an `Err` value: Protocol("Error reading frame header. Expected to read 7 bytes, but read 0")', ../src/libcore\result.rs:741
(...)
phsym commented 8 years ago

But it would probably be better to get the real reason (access-refused)

Antti commented 8 years ago

@phsym The real reason is rather implicit, we try to open a connection but server closes it without any notice, so we assume that the vhost is wrong. It's what the go client does.

phsym commented 8 years ago

OK. So I'm good with this. Getting an UnexpectedEOF-like error is still less confusing than a ByteOrder error.