Skip to content

PM2 cluster error "timeout: no answer from master in time" if the master is not already available when the client is created #242

@ighunter

Description

@ighunter

Following the example at https://github.com/animir/node-rate-limiter-flexible/wiki/PM2-cluster, we have one single-instance pm2 service for the RateLimiterClusterMasterPM2, and then we have another clustered service that uses new RateLimiterCluster() to initialize the rate-limiting, then we call .consume() in the client later.

If the order and timing of the service startup is as follows:

  1. new RateLimiterClusterMasterPM2(pm2) happens in the master service,
  2. new RateLimiterCluster() happens in the client services,

then all is good, and it works as expected.

However, if the order and timing of the service startup is as follows:

  1. new RateLimiterCluster() happens in a client service,
  2. then new RateLimiterClusterMasterPM2(pm2) happens in the master service,

then later when we call .consume() in the client we get this error:

Error: RateLimiterCluster timeout: no answer from master in time
     at Timeout._onTimeout (node_modules/rate-limiter-flexible/lib/RateLimiterCluster.js:188:14)
     at listOnTimeout (node:internal/timers:569:17)
     at process.processTimers (node:internal/timers:512:7)

Setting an arbitrarily large timeoutMs in the options passed to new RateLimiterCluster() such that the master should definitely have started within that many ms appears to make no difference.

This sequence of events also results in the same exception:

  1. new RateLimiterClusterMasterPM2(pm2) happens in the master service,
  2. new RateLimiterCluster() happens in the client services,
  3. One or more .consume()s happen successfully,
  4. The master service restarts while the client services continue to run uninterrupted,

then any further .consume() calls in the clients fail with RateLimiterCluster timeout: no answer from master in time

Is there something we should be doing differently, or is this something that can be fixed?

Node version: 18.17.1
rate-limiter-flexible version: 2.4.1
OS: Ubuntu 22.04.3 LTS

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions