It will never reconnect when connection has closed
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 42/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- javascript, nodejs, redis
調査の方向性
まず、報告されたネットワーク切断のシナリオを再現手順として使用し、node-redis 2.8.0 のソースで handle_offline_command、retry_strategy、再接続の経路を追跡します。closing、stream の状態、offline-queue の処理がどのように連携するかを確認します。サーバーが復旧したときに、一時的にネットワークアクセスを失った接続が再接続し、コマンドが NR_CLOSED で失敗したままにならなければ完了です。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- TypeScript
- スター
- 17.6k
- フォーク
- 2k
- 平均マージ
- 1日 22時間
- マージ済み PR(30日)
- 62
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
redis/node-redis のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
redis/node-redis#3664 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
After a MOVING handoff, a client never becomes ready again on reconnect対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 68/100
redis/node-redis#3705 ·
メンテナーはふだん 1 日以内に返信
-
accepted Bug
難易度 3/5 1〜2日 初心者へのやさしさ 52/100
redis/node-redis#3674 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Support Uint8Array values for zero-copy transfer to worker_threads対応中かも @umeshmore45 が 286 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
redis/node-redis#3106 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
`RedisClientType` type is slow to typecheck (TS performance issue)再び着手できるかも @nkaradzhov が 556 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンBug
redis/node-redis#2975 · コメント 30 件 · リアクション 27 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
redis/node-redis の issue をすべて見る
似ている issue
-
dependencies effort: small good first issue priority: low
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
TMHSDigital/screencast-mcp#509 ·
メンテナーはふだん 1 日以内に返信
-
from-review tech-debt testing
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
blamechris/chroxy#9520 ·
メンテナーはふだん 1 日以内に返信
-
area:web complexity:S priority:P2 type:chore
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
nahuelcostac/agent-hub#104 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
snaglet-org/snaglet#78 ·
メンテナーはふだん 1 日以内に返信
-
agent/guide documentation help wanted stage/010-actionable
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
kubestellar/console-marketplace#1101 ·
メンテナーはふだん 1 日以内に返信