Enforced Rate Limit does not reset

Hey all,

After changing my personal access token, my application throws rate limit error 429.

Things that happened before I got the 429 error:

→ I created a new personal access token (I have free plan) and forgot to delete the old one, but of course I exchanged the personal access token in my application right after I have crated the new one.

→ I also exchanged the access token of the other API (but I guess that does not matter)

→ I haven’t changed anything in the code! So seconds the code was running

This is the code in which I send requests to Asana:

asanaProjects.forEach(asanaProject => { 
setInterval(this.CollectResponse, 2000, asanaClientInstance, asanaProject); 
}

async CollectResponse(asanaClientInstance, asanaProject) {
    try {
      await asanaClientInstance.events.get(asanaProject, this.syncToken)
        .then((response) => { cool fancy things happen })
	});
    }	
});
The error message:
 RateLimitEnforced [Error]: Rate Limit Enforced
    at RateLimitEnforced.AsanaError (/home/runner/AsanaTicketBot/node_modules/asana/lib/errors/error.js:4:11)
    at new RateLimitEnforced (/home/runner/AsanaTicketBot/node_modules/asana/lib/errors/rate_limit_enforced.js:6:14)
    at Request._callback (/home/runner/AsanaTicketBot/node_modules/asana/lib/dispatcher.js:263:23)
    at Request.self.callback (/home/runner/AsanaTicketBot/node_modules/request/request.js:185:22)
    at Request.emit (node:events:390:28)
    at Request.emit (node:domain:475:12)
    at Request.<anonymous> (/home/runner/AsanaTicketBot/node_modules/request/request.js:1154:10)
    at Request.emit (node:events:390:28)
    at Request.emit (node:domain:475:12)
    at IncomingMessage.<anonymous> (/home/runner/AsanaTicketBot/node_modules/request/request.js:1076:12)
    at Object.onceWrapper (node:events:509:28)
    at IncomingMessage.emit (node:events:402:35)
    at IncomingMessage.emit (node:domain:475:12)
    at endReadableNT (node:internal/streams/readable:1343:12) {
  status: 429,
  value: { errors: [ [Object] ], retry_after: 172800 },
  retryAfterSeconds: 172800
}

asanaProjects is simply a list of project IDs.

The timeout duration does not increase after multiple requests. Even after the 172,800 seconds had passed, I got the error again after the first request I sent. Maybe I’m soft banned or on blacklist?

Thanks for your help :slight_smile:

@Phil_Seeman any idea? I can’t think of anything.

Hi @Jana_Mößner , welcome to the forum.

First, about limitations, you are limited to 150 query / minute if you use a free account.
Also, you can do a maximum of 50 simultaneous query.

That said, I don’t know how many projects you have, but if you have more than 50, you may get 429 because of the concurrency limit.

Your code is not running one by one, your first loop tells to query ALL projects at the same time, in 2000 ms…

I think you should try that instead:

asanaProjects.forEach(asanaProject => { 
  await this.CollectResponse(asanaClientInstance, asanaProject); 
}

Or, you can try in a recursive, where you will be able to add a delay between your calls:

CollectResponse(asanaClientInstance);

async CollectResponse(asanaClientInstance) {
   if (!asanaProjects.length) return;
   asanaProject = asanaProjects.pop();
    try {
      await asanaClientInstance.events.get(asanaProject, this.syncToken)
        .then((response) => { cool fancy things happen })
	});
    }
   setTimeout(CollectResponse, 1000, asanaClientInstance);
});
1 Like

Good catch!

Yeah, that’s right, in general that’s exactly what I want. Because I need to get the new event information from each of these projects at least in an interval of 2000 ms. Of course, I could do that step by step or recursive like your second approach, but I am not sure if that would solve the issue ?!

Maybe I should make sure that no requests to different projects happen at the same time in order not to exceed the rate limit. But tbh I am a bit confused why that approach works so well in the past :open_mouth:

Will try it out after my timeout ._. thanks a lot ^^

Maybe you now have more projects than before? If your code didn’t change, and you have now more than 50 projects, that can be the reason…

p.s. if you want it to run faster, start 5 threads using the recursive!

[1,2,3,4,5].forEach(i => CollectResponse(asanaClientInstance))

But now, you will not be limited by the concurrency limit, but by the max/per/minute.

1 Like

Also, maybe you changed your nodeJS configuration or version, and the “maxSocket” or “maxTotalSocket” property changed?

https://nodejs.org/api/http.html#agentmaxsockets

Just to be clear, whether requests are made towards the same or different projects is the same in terms of rate limit.

@Frederic_Malenfant you are definitely the best at rate limits :heart:

1 Like

Hey,

so I tried out a few things. The maxSocket/maxSocketTotal value is infinity, like it should per default.
To find the root of the rate limit enforcement, I wrote the code step by step.

this.CollectResponse(asanaClientInstance, asanaProjects[0]);
this.CollectResponse(asanaClientInstance, asanaProjects[1]);//triggers rate limit

The asanaProjects array contains only four environment variables representing project ids.

const asanaProjects = [process.env.FeedbackDiscordAsanaId, process.env.FeedbackInGameAsanaId,
process.env.BugsDiscordAsanaId, process.env.BugsInGameAsanaId];

I am not affected by the concurrency rate limit. And the standard rate limit is not reached with two request… I don’t understand what’s going on

And yes I updated my node packages, I would not rule out a connection between updates and error problems.

Edit: and even waiting for promise result of first request does not change anything