It will never reconnect when connection has closed
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ó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 42/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, nodejs, redis
Hướng nghiên cứu
Bắt đầu bằng cách lần theo handle_offline_command, retry_strategy và đường dẫn reconnect trong mã nguồn của node-redis 2.8.0, sử dụng tình huống ngắt kết nối mạng đã được báo cáo làm trường hợp tái hiện. Kiểm tra cách việc đóng kết nối, trạng thái stream và xử lý offline-queue tương tác với nhau. Được xem là hoàn tất khi một kết nối tạm thời mất quyền truy cập mạng có thể reconnect khi máy chủ hoạt động trở lại mà không khiến các lệnh thất bại với NR_CLOSED.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- 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ự
-
dependencies effort: small good first issue priority: low
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
TMHSDigital/screencast-mcp#509 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
from-review tech-debt testing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
blamechris/chroxy#9520 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area:web complexity:S priority:P2 type:chore
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
nahuelcostac/agent-hub#104 ·
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 77/100
snaglet-org/snaglet#78 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
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