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

connection.disconnect() fires the error handler with connection reset #462

Open
Gilwyad opened this issue Sep 13, 2017 · 5 comments
Open

Comments

@Gilwyad
Copy link

Gilwyad commented Sep 13, 2017

let connection = amqp.createConnection(...);
connection.on('ready', function () {
    connection.exchange(...,
                        function () {
                            connection.queue(...,
                                             function (q, messageCount, consumerCount) {
                                                 connection.disconnect();
                                             });
                        });
});

connection.on('error', function(e) {
    console.log(e);
}

How should I cleanly disconnect while also handling errors?

@soichih
Copy link

soichih commented Nov 3, 2017

Same issue. When I call connection.disconnect() I receive an error event.

 Error: read ECONNRESET
    at exports._errnoException (util.js:1020:11)
    at TCP.onread (net.js:568:26)

I have a script that uses amqp and I need to terminate it after all processing is done. However, calling disconnect won't kill the amqp's even loop(?) so my script keeps running. Calling disconnect() doesn't seem to end the event loop in this case.

@mcgG
Copy link

mcgG commented Nov 8, 2017

Same issue, calling disconnect() will trigger reconnect() so a new socket will open, this will cause mocha (>= 3.x) unit test cannot exit properly without --exit

@mcgG
Copy link

mcgG commented Nov 10, 2017

A temporary way to fix this issue is to call
self.connection.setImplOptions({reconnect: false});
before
connection.disconnect()
Then, connection will be reconnected by disconnect()'s exception

@rraghav773
Copy link

rraghav773 commented Apr 16, 2018

hey guys, I have found a fix. According to my understanding,when we call disconnect it sends "client disconnect" first and it receives "connectionCloseOk". On receiving the event, it first tries to call this.socket.end() function which is throwing the and possible reason for that is socket is no more available to communicate with server.

The fix is comment out or remove this.socket.end() and this.socket.destroy() will automatically destroys the socket, which is what a client intends when it calls a disconnect function. Finally, it would look like this

case methods.connectionCloseOk:
debug && debug("Received close-ok from server, closing socket");
this.socket.destroy();
break;

As I am beginner, correct me if something is wrong with this,

@soichih
Copy link

soichih commented Sep 23, 2018

Is there any update on this issue? I am still hit by this issue. (I am just killing the App manually at the end)

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