ConnectionTimeoutError: Connection timeout
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu với /api/cache/client.js, đặc biệt là redis.createClient({ url }) và client.connect(), sau đó so sánh hành vi kết nối với stack trace về timeout trong node_modules/@node-redis/client/dist/lib/client/socket.js. Tái hiện yêu cầu API và xác định lý do kết nối Redis bị timeout; hoàn tất khi cache vẫn báo hit hoặc miss mà không xuất hiện lặp lại các thông báo timeout và kết nối lại.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I am using this module to cache queries on a nextjs/node application.
Within nextjs I have a simple file within the /api folder (/api/cache/client.js) that contains the following code:
const redis = require("redis");
const REDIS_CLIENT_URI = process.env.REDIS_URL || "redis://127.0.0.1:6379";
let client = null;
const onRedisError = (err) => {
console.error(err);
};
const onRedisConnect = () => {
console.log("Redis connected");
};
const onRedisReconnecting = () => {
console.log("Redis reconnecting");
};
const onRedisReady = () => {
console.log("Redis ready!");
};
async function redisClient() {
try {
if (client === null) {
client = redis.createClient({
url: REDIS_CLIENT_URI,
});
await client.connect();
}
client.on("error", onRedisError);
client.on("connect", onRedisConnect);
client.on("reconnecting", onRedisReconnecting);
client.on("ready", onRedisReady);
return client;
} catch (e) {
console.log("not connected");
console.log(e.message);
return null;
}
}
async function redisGet(key, func) {
try {
const client = await redisClient();
if (client === null) {
throw new Error("Redis is not connected");
}
const data = await client.get(key);
if (data === null) {
console.log("miss");
const query = await func();
await redisSet(key, JSON.stringify(query));
return query;
} else {
console.log("hit");
return JSON.parse(data);
}
} catch (e) {
console.log(e.message);
return await func();
}
}
async function redisSet(key, data) {
try {
const client = await redisClient();
if (client === null) {
throw new Error("Redis is not connected");
}
await client.set(key, data, { EX: 86400 * 31 });
} catch (e) {
console.log(e.message);
}
}
module.exports.redisGet = redisGet;
I then require this file in any /api files where I need to use redis to cache the results of any asycnhronous function that makes a call to an external API e.g.
const { redisGet } = require("../cache/client");
export default async function handler(req, res) {
try {
const data = JSON.parse(req.body);
const query = await redisGet(
`${data.customer_id}:${data.fromDate}/${data.toDate}`,
async () => {
try {
const res = await fetch(
`https://jsonplaceholder.typicode.com/comments`
);
const data = await res.json();
return data;
} catch (e) {
console.log(e);
throw e;
}
}
);
console.log(query);
res.status(200).send({ query });
} catch (e) {
console.log(e);
console.log(e.message);
res.status(500).json(e.message);
}
}
}
This works fine because I am able to get the commands in my output such as hit and miss whenever I call any of the API endpoints where I am using redisGet, however, my server also seems to constantly be giving me a connection timeout error followed by Redis reconnecting:
at TLSSocket.<anonymous> (/Users/kamrankhan/Sites/2020/visifii/visifii/node_modules/@node-redis/client/dist/lib/client/socket.js:169:124)
at Object.onceWrapper (node:events:509:28)
at TLSSocket.emit (node:events:390:28)
at TLSSocket.emit (node:domain:475:12)
at TLSSocket.Socket._onTimeout (node:net:486:8)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7)
Redis reconnecting
I don't know what I'm doing wrong here. I have also set the timeout config time to 10000 and also set the maxmemory-policy config to allkeys-lru. Can anyone nudge me in the right direction? Am I missing something? Any help would be appreciated!
Environment:
- Node.js Version:
- v16.10.0
- Redis Server Version:
- Redis server v=6.2.6 sha=00000000:0 malloc=libc bits=64 build=c6f3693d1aced7d9
- Node Redis Version:
- [email protected]
- Platform:
- Mac OS Mojave 10.14.6
- Ngôn ngữ chính
- TypeScript
- Star
- 17.6k
- Fork
- 2k
- Merge trung bình
- 1 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 62
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của redis/node-redis
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
redis/node-redis#3664 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
After a MOVING handoff, a client never becomes ready again on reconnectCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 68/100
redis/node-redis#3705 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
accepted Bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
redis/node-redis#3674 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Support Uint8Array values for zero-copy transfer to worker_threadsCó thể đã có người làm @umeshmore45 đã nhận 286 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
redis/node-redis#3106 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`RedisClientType` type is slow to typecheck (TS performance issue)Có thể làm lại được @nkaradzhov đã nhận 556 ngày trước và không có pull request nào đang mở. Đang mởBug
redis/node-redis#2975 · 30 bình luận · 27 reaction · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của redis/node-redis
Issue tương tự
-
agent/guide documentation help wanted stage/010-actionable
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
kubestellar/console-marketplace#1101 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Java Edition Tests
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
JSPrismarine/JSPrismarine#4178 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
totec448-spec/chat-on-steroids#2394 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
github_actions
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
StellarHyperion/stellarhyperion-backend#499 ·
Maintainer thường phản hồi trong vòng 1 ngày