cloudamqp / amqp-client.js

AMQP 0-9-1 TypeScript client both for Node.js and browsers (using WebSocket)
https://cloudamqp.github.io/amqp-client.js/
Apache License 2.0
200 stars 19 forks source link

Heartbeat not honored? #95

Open thundo opened 10 months ago

thundo commented 10 months ago

Hi all!

I'm creating a channel with heartbeat enabled to a vanilla rabbitmq server. Connection/channel are good. Hearbeats are flowing (as you can see from the wireshark trace).

Later on, I physically disconnect the server machine's ethernet. My expectation is that after 2 heartbeats the connection will crash.

Instead, no heartbeats are exchanged anymore after that. The connection just hangs there indefinitely.

This is the code

import {AMQPClient} from '@cloudamqp/amqp-client';

const run = async () => {
    const amqp = new AMQPClient('amqp://test:test@mercurius?heartbeat=60');

    console.log(`Connecting to RabbitMQ ${amqp.host}:${amqp.port}, tls=${amqp.tls}, vhost=${amqp.vhost}, user=${amqp.username}...`);
    if (!amqp.heartbeat) {
        console.log('AMQPClient: heartbeat is disabled');
    } else {
        console.log(`AMQPClient: heartbeat set to ${amqp.heartbeat}`);
    }
    const conn = await amqp.connect();
    const channel = await conn.channel();
    console.log(`RabbitMQ channel ${channel.id} opened`);

    console.log(channel);
};

run();

Output

Connecting to RabbitMQ mercurius:5672, tls=false, vhost=/, user=test...
AMQPClient: heartbeat set to 60
RabbitMQ channel 1 opened
<ref *1> AMQPChannel {
  consumers: Map(0) {},
  rpcQueue: Promise { undefined },
  unconfirmedPublishes: [],
  closed: false,
  confirmId: 0,
  connection: AMQPClient {
    closed: false,
    channelMax: 2047,
    logger: Object [console] {
      log: [Function: log],
      warn: [Function: warn],
      dir: [Function: dir],
      time: [Function: time],
      timeEnd: [Function: timeEnd],
      timeLog: [Function: timeLog],
      trace: [Function: trace],
      assert: [Function: assert],
      clear: [Function: clear],
      count: [Function: count],
      countReset: [Function: countReset],
      group: [Function: group],
      groupEnd: [Function: groupEnd],
      table: [Function: table],
      debug: [Function: debug],
      info: [Function: info],
      dirxml: [Function: dirxml],
      error: [Function: error],
      groupCollapsed: [Function: groupCollapsed],
      Console: [Function: Console],
      profile: [Function: profile],
      profileEnd: [Function: profileEnd],
      timeStamp: [Function: timeStamp],
      context: [Function: context]
    },
    textEncoder: { encoding: 'utf-8' },
    bufferPool: [],
    vhost: '/',
    username: 'test',
    platform: 'node v18.15.0 win32 x64',
    channels: [ [AMQPChannel], [Circular *1] ],
    onerror: [Function (anonymous)],
    frameMax: 4096,
    heartbeat: 60,
    tls: false,
    tlsOptions: undefined,
    host: 'mercurius',
    port: 5672,
    insecure: false,
    framePos: 0,
    frameSize: 0
  },
  id: 1,
  onerror: [Function (anonymous)],
  resolveRPC: [Function (anonymous)],
  rejectRPC: [Function (anonymous)]
}

Wireshark trace image

Am I under the wrong assumption that the connection should crash? Thanks

dentarg commented 10 months ago

Which version of amqp-client.js are you using?

thundo commented 10 months ago

Which version of amqp-client.js are you using?

Latest published, 3.1.1

icastillejogomez commented 9 months ago

I also have the same problem

frankdejonge commented 7 months ago

The same behaviour occurs when the credentials of a user are changed while they have active connections. No errors, just a stale connection and nothing is resolved anymore. This includes on publishing as well as consuming messages.