Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
Axios call stuck after using rate limiter to block request

I'm using rate limiter to throttle my API calls. However, after the rate limiter rejects/blocks, when the time comes for the rate limiter to allows API calls again, suddenly the app stuck inside the Axios call.

Here's an example code snippet. Any help is appreciated.

const express = require("express");
const cors = require("cors");
const axios = require("axios");

//initialise express
const app = express();

// rate limiter initialize
const { RateLimiterMemory } = require('rate-limiter-flexible');
const rateLimiter = new RateLimiterMemory({
  points: 4, //Maximum number of points can be consumed over duration
  duration: 5, //Number of seconds before consumed points are reset.
});

// Body parser
app.use(express.json());

// Cross origin resource sharing
app.use(cors());

async function test429() {
  var success;    
  var config = {
    method: "get",
    url: "https://www.cloudflare.com/rate-limit-test"
  };  
  await axios(config)
    .then ((response) => {
        console.log("pass");
        success = response.status;
    })
    .catch (async (err) => {
      console.log("failed ", err.response.status);
      success = err.response.status;
    })

  return success;  
}

async function getTest() {
  var index = 0;
  while (index < 100) {        
    await rateLimiter.consume("test", 1) // Consume 1 points
      .then(async (rateLimiterRes) => {
        // Allowed            
        console.log("check API call no ", index);
        const test = await test429();
        console.log("return status : ", test);
        index = index + 1;
        if (test=="429") {
          const toDate = (new Date()).toISOString().slice(0, 19).replace(/-/g, "/").replace("T", " ");
          console.log("error 429 returned, block for 61s since", toDate);
          rateLimiter.block("test", 61); // block for 61sec              
        }        
      })
      .catch((rej) => {
        // Blocked          
        
        
      });  
  }
  console.log("done");
}

getTest();
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!