From ab8627c9faa9d16af21607cf5ed20650ba838584 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Thu, 3 Aug 2023 20:56:50 +0000 Subject: [PATCH] Fix monitor retrying failed etcd connection in an infinite loop without pauses --- mon/mon.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/mon/mon.js b/mon/mon.js index 2904b681..3fbf3af7 100644 --- a/mon/mon.js +++ b/mon/mon.js @@ -539,10 +539,18 @@ class Mon { retries = 1; } + const tried = {}; while (retries < 0 || retry < retries) { const cur_addr = this.pick_next_etcd(); const base = 'ws'+cur_addr.substr(4); + let now = Date.now(); + if (tried[base] && now-tried[base] < timeout) + { + await new Promise(ok => setTimeout(ok, timeout-(now-tried[base]))); + now = Date.now(); + } + tried[base] = now; const ok = await new Promise((ok, no) => { const timer_id = setTimeout(() => @@ -1788,10 +1796,18 @@ class Mon { retries = 1; } + const tried = {}; while (retries < 0 || retry < retries) { retry++; const base = this.pick_next_etcd(); + let now = Date.now(); + if (tried[base] && now-tried[base] < timeout) + { + await new Promise(ok => setTimeout(ok, timeout-(now-tried[base]))); + now = Date.now(); + } + tried[base] = now; const res = await POST(base+path, body, timeout); if (res.error) {