From 807070282cecf59e4819fbca598ce588e451f280 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 18 May 2021 13:41:57 +0530 Subject: [PATCH] fix: Abort redis retries only for esbuild --- esbuild/esbuild.js | 4 ++-- esbuild/utils.js | 17 ++++++++++++++++- node_utils.js | 20 +++++++++----------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/esbuild/esbuild.js b/esbuild/esbuild.js index a286acd4ed..ecf0d49511 100644 --- a/esbuild/esbuild.js +++ b/esbuild/esbuild.js @@ -21,9 +21,9 @@ let { log, log_warn, log_error, - bench_path + bench_path, + get_redis_subscriber } = require("./utils"); -let { get_redis_subscriber } = require("../node_utils"); let argv = yargs .usage("Usage: node esbuild [options]") diff --git a/esbuild/utils.js b/esbuild/utils.js index b6c2422292..301797d35e 100644 --- a/esbuild/utils.js +++ b/esbuild/utils.js @@ -110,6 +110,20 @@ function log(...args) { console.log(...args); // eslint-disable-line no-console } +function get_redis_subscriber(kind) { + // get redis subscriber that aborts after 50 connection attempts + let { get_redis_subscriber: get_redis } = require("../node_utils"); + return get_redis(kind, { + retry_strategy: function(options) { + // abort after 50 connection attempts + if (options.attempt > 50) { + return undefined; + } + return Math.min(options.attempt * 100, 2000); + } + }); +} + module.exports = { app_list, bench_path, @@ -126,5 +140,6 @@ module.exports = { get_cli_arg, log, log_warn, - log_error + log_error, + get_redis_subscriber }; diff --git a/node_utils.js b/node_utils.js index fb0a6d8478..c38caa2b3d 100644 --- a/node_utils.js +++ b/node_utils.js @@ -38,19 +38,17 @@ function get_conf() { return conf; } -function get_redis_subscriber(kind="redis_socketio") { +function get_redis_subscriber(kind="redis_socketio", options=null) { const conf = get_conf(); const host = conf[kind] || conf.redis_async_broker_port; - return redis.createClient({ - host, - retry_strategy: function(options) { - // abort after 5 connection attempts - if (options.attempt > 5) { - return undefined; - } - return Math.min(options.attempt * 100, 2000); - }, - }); + + if (options) { + return redis.createClient({ + host, + ...options + }); + } + return redis.createClient(host); } module.exports = {