It will never reconnect when connection has closed
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 42/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- javascript, nodejs, redis
Direzione di ricerca
Inizia tracciando handle_offline_command, retry_strategy e il percorso di riconnessione nel codice sorgente di node-redis 2.8.0, usando lo scenario di disconnessione di rete segnalato come riproduzione. Verifica come interagiscono la chiusura, lo stato dello stream e la gestione della coda offline. Il lavoro è completo quando una connessione che perde temporaneamente l’accesso alla rete si riconnette quando il server torna disponibile, senza lasciare che i comandi falliscano con NR_CLOSED.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Hi, in the past few years, I find a critical bug in my production env. My production env use node-redis : 2.7.1. When the network disconnect , the node-redis will run the retry_strategy that I specified,and then the node-redis connection closed.But node-redis will not reconnect to the redis server again when the network is ok. So my production env always throw an error: The connection is already closed in the error log, always. Then I have to restart my node server to fix this. In my production env , the retry_strategy is:
retry_strategy: function (options) {
// console.log('retry_strategy', options);
if (options.error && options.error.code === 'ECONNREFUSED') {
// End reconnecting on a specific error and flush all commands with
// a individual error
return new Error('The server refused the connection');
}
if (options.total_retry_time > 1000 * 60 * 60) {
// End reconnecting after a specific timeout and flush all commands
// with a individual error
return new Error('Retry time exhausted');
}
if (options.attempt > 10) {
// End reconnecting with built in error
return new Error('Attempt time exhausted');
}
// reconnect after
return Math.min(options.attempt * 100, 3000);
}
I doubt a very long time, why this would happended. So I dig into the source codes , the node-redis version is 2.8.0. It has this bug too. Then I find the reason:
function handle_offline_command (self, command_obj) {
var command = command_obj.command;
var err, msg;
if (self.closing || !self.enable_offline_queue) {
command = command.toUpperCase();
if (!self.closing) {
if (self.stream.writable) {
msg = 'The connection is not yet established and the offline queue is deactivated.';
} else {
msg = 'Stream not writeable.';
}
} else {
msg = 'The connection is already closed.';
}
err = new errorClasses.AbortError({
message: command + " can't be processed. " + msg,
code: 'NR_CLOSED',
command: command
});
if (command_obj.args.length) {
err.args = command_obj.args;
}
utils.reply_in_order(self, command_obj.callback, err);
} else {
debug('Queueing ' + command + ' for next server connection.');
self.offline_queue.push(command_obj);
}
self.should_buffer = true;
}


When the connection is down, then the ready is false and stream is not writable. And handle_offline_command will handle this .At this time the closing is always true, so it will throw an AbortError. So I donot know why retry connection to de redis server in this scope.
I fix this code like this, and it works:
function handle_offline_command (self, command_obj) {
var command = command_obj.command;
var err, msg;
if (self.closing || !self.enable_offline_queue) {
if(self.stream == null || self.stream.destroyed){
retry_connection(self, null);
}else{
self.offline_queue.push(command_obj);
}
// command = command.toUpperCase();
// if (!self.closing) {
// if (self.stream.writable) {
// msg = 'The connection is not yet established and the offline queue is deactivated.';
// } else {
// msg = 'Stream not writeable.';
// }
// } else {
// msg = 'The connection is already closed.';
// }
// err = new errorClasses.AbortError({
// message: command + " can't be processed. " + msg,
// code: 'NR_CLOSED',
// command: command
// });
// if (command_obj.args.length) {
// err.args = command_obj.args;
// }
// utils.reply_in_order(self, command_obj.callback, err);
} else {
debug('Queueing ' + command + ' for next server connection.');
self.offline_queue.push(command_obj);
}
self.should_buffer = true;
}
I donot know it will has any other logic code relatively, although I fix it and it work well . So I hope you give me a reliable solution, thks.The code is a little bit messy, so I very want to rewrite your node-redis using asyn await. But I have no time in this year.
- Lingua principale
- TypeScript
- Stelle
- 17.6k
- Fork
- 2k
- Merge medio
- 1g 22h
- PR unite (30g)
- 62
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di redis/node-redis
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
redis/node-redis#3664 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
After a MOVING handoff, a client never becomes ready again on reconnectForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 68/100
redis/node-redis#3705 ·
I maintainer di solito rispondono entro 1 giorno
-
accepted Bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 52/100
redis/node-redis#3674 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Support Uint8Array values for zero-copy transfer to worker_threadsForse già presa @umeshmore45 l’ha presa 286 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
redis/node-redis#3106 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
`RedisClientType` type is slow to typecheck (TS performance issue)Forse di nuovo libera @nkaradzhov l’ha presa 556 giorni fa e non c’è nessuna pull request aperta. ApertaBug
redis/node-redis#2975 · 30 commenti · 27 reazioni · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di redis/node-redis
Issue simili
-
agent/guide documentation help wanted stage/010-actionable
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
kubestellar/console-marketplace#1101 ·
I maintainer di solito rispondono entro 1 giorno
-
Java Edition Tests
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
JSPrismarine/JSPrismarine#4178 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
totec448-spec/chat-on-steroids#2394 ·
I maintainer di solito rispondono entro 1 giorno
-
github_actions
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
StellarHyperion/stellarhyperion-backend#499 ·
I maintainer di solito rispondono entro 1 giorno