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

missed heartbeats do not seem to terminate connection

Open jclulow opened this issue 9 years ago • 5 comments

If I set the heartbeat option (e.g. to 5), the client appears to correctly negotiate the heartbeat interval with RabbitMQ. The "heartbeat" event is emitted at the correct interval when the server is ending heartbeats. If I disable the server while watching this output, the heartbeats (obviously) stop arriving but the client does not signal an error until I try to send a message -- even if this is many intervals later.

I'm not yet completely familiar with the relatively esoteric socket state tracking being used in this library, but I don't see how this logic can be correct:

Connection.prototype._inboundHeartbeatTimerReset = function () {
...
    this._inboundHeartbeatTimer = setTimeout(function () {
      if(self.socket.readable)
        self.emit('error', new Error('no heartbeat or data in last ' + gracePeriod + ' seconds'));
    }, gracePeriod * 1000);
...

Specifically: if no data has arrived (heartbeats or otherwise), why would the socket be readable?

jclulow avatar Jan 05 '16 06:01 jclulow

I'm in the same position. Unfortunately I don't think this library is being actively maintained so we might need to find a solution ourselves

chriswiggins avatar Mar 21 '16 22:03 chriswiggins

I'm also running in a similar issue. Depending of situation heartbeat does sometime seems to kick in ie. I did get "no heartbeat or data in last xx seconds" exception once, but most of the time I don't.

Listening for the "close" event I can see connection being closed between the 2 heartbeat, so I suspect the problem is with the if(self.socket.readable) check which no longer check heartbeat after socket is closed.

@jclulow @chriswiggins did you find a solution to this problem?

siboulet avatar Apr 25 '16 16:04 siboulet

@siboulet I'm working around it in my library -- https://github.com/joyent/node-urclient/blob/master/lib/mq.js#L362-L375

jclulow avatar Apr 25 '16 21:04 jclulow

Anyone tried the new heartbeatForceReconnect option introduced in the latest 0.2.6 release?

https://github.com/postwait/node-amqp/commit/4a382125d18d74fdffa450afe5f46c0cff1aef57

siboulet avatar Jun 27 '16 22:06 siboulet

4a38212 this fix is also failing and the issue is the same

DJMit-alt avatar Sep 12 '18 07:09 DJMit-alt