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

connect() calls its own callback multiple times upon error #354

Closed
dotkas opened this issue May 24, 2017 · 6 comments
Closed

connect() calls its own callback multiple times upon error #354

dotkas opened this issue May 24, 2017 · 6 comments

Comments

@dotkas
Copy link

dotkas commented May 24, 2017

Hello.

If I try to connect to a queue using invalid credentials, such as this:

amqp.connect(config.endpoints.textQueue + '?heartbeat=30', (err, conn) => {
    if (err) {
        return callback(`Unable to connect to rabbitMQ (${url.parse(config.endpoints.textQueue).host}), is there a connection? Aborting: ${err}`);
    }
(...)
}

The callback is called two times with an err parameter. First one that gives me access denied, and then one with a socket close.

This obviously causes my code to throw an exception due to the callback already having been called.

Is this working as intended?

First callback:
Handshake terminated by server: 403 (ACCESS-REFUSED) with message \"ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.\"

Second:
Socket closed abruptly during opening handshake

Thank you in advance.

@cressie176
Copy link
Collaborator

cressie176 commented May 25, 2017

I get the same. Looks like a bug. Could be fixed by wrapping openCallback so that it only ever is executed once, or by checking / setting a flag wherever openCallback is called, however both of these solutions would mean suppressing socket errors that occurred after successfully connecting. @squaremo thoughts?

@cressie176
Copy link
Collaborator

I suspect this is the root cause of onebeyond/rascal#17

@tcort
Copy link

tcort commented Aug 21, 2017

I ran into this issue as well. As a work around, I used _.once(fn) to wrap the callback I passed to amqp.connect() as described here: onebeyond/rascal#17 (comment)

@cressie176
Copy link
Collaborator

This seems better in 0.5.2, however I'm I've just hit a similar problem with errors returned from connection.createChannel.

Steps to reproduce

  1. Create Connection
  2. Create Channel
  3. Subscribe (without optional callback)
  4. Close connection

If the subscription hasn't complete by the time the connection is closed, amqplib executes the create channel callback multiple times.

@AbdulRahmanAlHamali
Copy link

This bug, combined with the retry code presented here:

https://www.cloudamqp.com/docs/nodejs.html

Can DDoS RabbitMQ. It's a shame it hasn't been addressed yet

@cressie176
Copy link
Collaborator

Duplicate of #402

@cressie176 cressie176 marked this as a duplicate of #402 May 8, 2022
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

4 participants