node-amqp icon indicating copy to clipboard operation
node-amqp copied to clipboard

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

Open Gilwyad opened this issue 8 years ago • 5 comments

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?

Gilwyad avatar Sep 13 '17 15:09 Gilwyad

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.

soichih avatar Nov 03 '17 21:11 soichih

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 avatar Nov 08 '17 02:11 mcgG

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

mcgG avatar Nov 10 '17 06:11 mcgG

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,

rraghav773 avatar Apr 16 '18 07:04 rraghav773

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

soichih avatar Sep 23 '18 16:09 soichih