ConnectionTimeoutError: Connection timeout
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
Empieza por /api/cache/client.js, especialmente por redis.createClient({ url }) y client.connect(), y compara después el comportamiento de la conexión con el stack trace del timeout en node_modules/@node-redis/client/dist/lib/client/socket.js. Reproduce la solicitud de la API y determina por qué la conexión de Redis alcanza el tiempo de espera; se considera terminado cuando la caché sigue indicando hits o misses sin mensajes repetidos de timeout y reconexión.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- TypeScript
- Estrellas
- 17.6k
- Forks
- 2k
- Merge medio
- 1 d 22 h
- PR fusionados (30 d)
- 62
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de redis/node-redis
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
redis/node-redis#3664 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
After a MOVING handoff, a client never becomes ready again on reconnectPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 68/100
redis/node-redis#3705 ·
Los mantenedores suelen responder en 1 día
-
accepted Bug
Dificultad 3/5 1-2 días Aptitud para principiantes 52/100
redis/node-redis#3674 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Support Uint8Array values for zero-copy transfer to worker_threadsPosiblemente ocupada @umeshmore45 la tomó hace 286 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
redis/node-redis#3106 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
`RedisClientType` type is slow to typecheck (TS performance issue)Quizá libre de nuevo @nkaradzhov la tomó hace 556 días y no hay ningún pull request abierto. AbiertoBug
redis/node-redis#2975 · 30 comentarios · 27 reacciones · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de redis/node-redis
Issues similares
-
agent/guide documentation help wanted stage/010-actionable
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
kubestellar/console-marketplace#1101 ·
Los mantenedores suelen responder en 1 día
-
Java Edition Tests
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
JSPrismarine/JSPrismarine#4178 · 1 comentario · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
totec448-spec/chat-on-steroids#2394 ·
Los mantenedores suelen responder en 1 día
-
github_actions
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
StellarHyperion/stellarhyperion-backend#499 ·
Los mantenedores suelen responder en 1 día