Upstash Ratelimit Error in GH Action
FleetAdmiralJakob opened this issue · 8 comments
Hi, while running my GH Action I got this error from upstash:
Failed to record analytics TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:117***:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async HttpClient.request (file:///home/runner/work/Weather-App/Weather-App/node_modules/.pnpm/@upstash+redis@1.22.1/node_modules/@upstash/redis/esm/pkg/http.js:90:23)
at async HIncrByCommand.exec (file:///home/runner/work/Weather-App/Weather-App/node_modules/.pnpm/@upstash+redis@1.22.1/node_modules/@upstash/redis/esm/pkg/commands/command.js:55:35)
at async /home/runner/work/Weather-App/Weather-App/node_modules/.pnpm/@upstash+core-analytics@0.0.6/node_modules/@upstash/core-analytics/dist/index.js:125:9
at async Promise.all (index 0)
at async Analytics.ingest (/home/runner/work/Weather-App/Weather-App/node_modules/.pnpm/@upstash+core-analytics@0.0.6/node_modules/@upstash/core-analytics/dist/index.js:120:5)
at async Analytics.record (/home/runner/work/Weather-App/Weather-App/node_modules/.pnpm/@upstash+ratelimit@1.0.0/node_modules/@upstash/ratelimit/dist/index.js:60:5)
at async Promise.all (index 1) {
cause: Error: getaddrinfo ENOTFOUND feasible-urchin-36877.upstash.io,
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26) {
errno: -***08,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'feasible-urchin-36877.upstash.io,'
}
}
With this Ratelimit code:
const ratelimit = new Ratelimit({
redis,
limiter: Ratelimit.slidingWindow(
parseInt(env.UPSTASH_RATELIMITER_TOKENS_PER_TIME),
UPSTASH_RATELIMITER_TIME_INTERVAL,
),
analytics: true,
prefix: "@upstash/ratelimit",
});
const rateLimitMiddleware = t.middleware(async ({ ctx, path, next }) => {
const identifier = `${ctx.ip}:${path}`;
// log.debug("identifier", { identifier });
const { success, remaining } = await ratelimit.limit(identifier);
// log.debug("remaining", { remaining });
ctx.res.setHeader(
"X-RateLimit-Limit",
env.UPSTASH_RATELIMITER_TOKENS_PER_TIME,
);
ctx.res.setHeader("X-RateLimit-Remaining", remaining);
if (!success) {
log.warn("Rate limit exceeded", { ip: identifier });
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Rate limit exceeded",
});
}
return next();
});
Hey @FleetAdmiralJakob ,
do you get the same error when you turn off the ratelimit analytics? Can you try it that way so that we can trace the problem
analytics: false
in the ratelimit config
With analytics false it is not giving an error. But I will turn analytics true because I need the information. So that is not a solution.
Okey no problem, so we know where the problem most likely occurs rn. We'll investigate this error and respond to you as soon as possible
Thank you
Hi, any updates on this?
Hey, sorry for the latency. Having a look at it, we've realized that your endpoint contains a comma at the end.
hostname: 'feasible-urchin-36877.upstash.io,'
Could you copy the credentials from the Upstash console fresh, and try once again making sure that credentials are correct? This may be the root cause