-
Notifications
You must be signed in to change notification settings - Fork 476
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 callback invoked twice on authentication failure #402
Comments
I've had similar problems relating to timeouts, but they were fixed in 0.5.2 (it was actually worse because I got a second successful connection). This was my workaround. |
Thanks @cressie176. I've ended up with something similar for now |
I've encountered the same issue:
How to reproduce? NOTE: I use own auto-reconnect module to handle connection errors a bit similar to rascal. Tested with: |
Still an issue... const amqp = require('amqplib/callback_api');
let i = 0;
amqp.connect('amqp://foo:bar@localhost:5672', (err, connection) => {
console.log(i++, err);
})
This issue occurs when after kicking off the handshake the server is unhappy with something and replies with a ConnectionClose. amqplib invokes the callback with the error, but leaves the previously registered stream event handlers intact. A short while later the socket detects that it has been closed by the server, the end event it fired, causing the callback to be invoked a second time. It also looks like there may be other problems with this code. There are a few places (1, 2, 3, 4 & 5) where it bails without notifying the server or closing the socket. If I'm right and the application retries instead of stopping we'll be left with a socket leak. If the dangling socket errors or is closed by the server then the callback will be called twice at that point. |
A quick experiment suggests removing the event handlers then ending the stream anywhere the code bails should do the job. function bail(err) {
self.stream.removeAllListeners();
self.stream.end();
openCallback(err);
} |
Seems done called twice on invalid options (PR 667 beat me to it. Included in v0.9.0 |
I'm testing some error cases, specifically authentication failures. I've noticed that my #connect callback will be invoked twice: once for the authentication failure, then, roughly a second later, another invocation for the socket being forcibly closed. Is this the expected behavior?
For reference, the first error is:
The second error is:
And my test code is:
I'm using node 8.2.1 and amqplib 0.5.2.
Thanks for any clarification on this.
The text was updated successfully, but these errors were encountered: