Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #601 from godwokenrises/fix-ws-batch-ratelimit
Browse files Browse the repository at this point in the history
fix(1.10): wrong return in the loop of wsApplyBatchRateLimitByIp
  • Loading branch information
RetricSu authored Jan 11, 2023
2 parents 16f65e7 + 75f6f84 commit f1703b7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/api-server/src/rate-limit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export async function wsApplyBatchRateLimitByIp(
): Promise<JSONRPCError[] | undefined> {
const ip = getIp(req);
const methods = Object.keys(accessGuard.rpcMethods);
if (methods.length === 0) {
return undefined;
}

for (const targetMethod of methods) {
const count = calcMethodCount(objs, targetMethod);
if (count > 0 && ip != null) {
Expand All @@ -30,17 +34,18 @@ export async function wsApplyBatchRateLimitByIp(
};

logger.debug(
`Rate Limit Exceed, ip: ${ip}, method: ${targetMethod}, ttl: ${remainSecs}s`
`WS Batch Rate Limit Exceed, ip: ${ip}, method: ${targetMethod}, ttl: ${remainSecs}s`
);

return new Array(objs.length).fill(error);
} else {
await accessGuard.updateCount(targetMethod, ip, count);
}
}

return undefined;
// continue next loop
}

return undefined;
}

export async function wsApplyRateLimitByIp(
Expand Down

0 comments on commit f1703b7

Please sign in to comment.