RocketChat/Rocket.Chat · error · Meteor.Error

too-many-requests

too-many-requests

Error message

too-many-requests

What it means

POST /api/v1/method.call/:method bridges REST to DDP method invocation. Before calling Meteor.callAsync it runs DDPRateLimiter._increment then _check keyed on {userId, clientAddress, type: 'method', name: method, connectionId} (misc.ts:662-669); when a matching rate-limit rule trips, the call aborts with Meteor.Error('too-many-requests') and details.timeToReset (ms until the window frees). Because _increment runs first, every rejected request also consumed quota - immediate retries extend the block. The endpoint's own catch then serializes this error into the DDP-style result envelope (mountResult), so callers see it inside the method-call payload rather than as a standard REST error body.

Solutions

  1. Parse the returned EJSON error and read details.timeToReset - wait at least that long (plus margin) before retrying
  2. Throttle or batch the client so it stays under the rule's limit instead of retrying into it
  3. Ask the workspace admin to review the DDPRateLimiter rule for that method name and raise the limit if the traffic is legitimate
  4. Prefer the native REST endpoints over the method.call bridge - they do not pass through the method rate limiter

Example fix

// before
 while (true) {
   await api.post('/api/v1/method.call/sendMessage', { message: EJSON.stringify({ method: 'sendMessage', params, id }) });
 }

 // after: respect timeToReset
 try {
   await api.post('/api/v1/method.call/sendMessage', { message: EJSON.stringify({ method: 'sendMessage', params, id }) });
 } catch (err) {
   if (err.error === 'too-many-requests') {
     await new Promise((r) => setTimeout(r, (err.details?.timeToReset ?? 1000) + 100));
   }
 }
Defensive patterns

Strategy: retry

Validate before calling

if (callsPerSecond(method) > configuredLimit(method)) {
  await throttle(method, configuredLimit(method)); // client-side limiter mirroring the server rule
}
await api.post(`/api/v1/method.call/${method}`, { message: EJSON.stringify({ method, params, id }) });

Try / catch

try {
  return await api.post(`/api/v1/method.call/${method}`, { message: EJSON.stringify({ method, params, id }) });
} catch (err) {
  if (err?.error === 'too-many-requests') {
    const wait = (err.details?.timeToReset ?? 1000) + 100; // ms; each rejected call already consumed quota
    await new Promise((r) => setTimeout(r, wait));
    return api.post(`/api/v1/method.call/${method}`, { message: EJSON.stringify({ method, params, id }) }); // retry once
  }
  throw err;
}

Prevention

When it happens

Trigger: Repeating the same DDP method (sendMessage, login, typing notifications...) through method.call faster than a configured DDPRateLimiter rule allows; several scripts sharing one user token or one source IP so their requests pool into the same bucket.

Common situations: Polling loops that invoke a method per tick; brute-force protections on login methods; office NAT causing clientAddress bucket collisions; connectionId derived from the token hash so one token equals one bucket.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@2a7de45707 (2026-08-18). Data as JSON: /api/errors/030c3a6dfde1ad74. Report an issue: GitHub.

Appendix: source

Thrown at apps/meteor/server/api/v1/misc.ts:666

			this.token ||
			crypto
				.createHash('sha256')
				.update((this.requestIp ?? '') + this.user._id)
				.digest('hex');

		const rateLimiterInput = {
			userId: this.userId,
			clientAddress: this.requestIp,
			type: 'method',
			name: method,
			connectionId,
		};

		try {
			DDPRateLimiter._increment(rateLimiterInput);
			const rateLimitResult = DDPRateLimiter._check(rateLimiterInput);
			if (!rateLimitResult.allowed) {
				throw new Meteor.Error('too-many-requests', DDPRateLimiter.getErrorMessage(rateLimitResult), {
					timeToReset: rateLimitResult.timeToReset,
				});
			}

			return API.v1.success(mountResult({ id, result: await Meteor.callAsync(method, ...params) }));
		} catch (err) {
			logMethodCallError(method, err);

			return API.v1.failure(mountResult({ id, error: err }));
		}
	},
);

API.v1.post(
	'method.callAnon/:method',
	{
		authRequired: false,
		userWithoutUsername: true,

View on GitHub (pinned to 2a7de45707)