From 7006875a2411dda11dd19d29d2f2b75488feea7a Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Tue, 9 Mar 2021 01:46:57 +0300 Subject: [PATCH] Make monitor stick to one etcd until the restart --- mon/mon.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mon/mon.js b/mon/mon.js index c8ba1cda..ac5cba60 100644 --- a/mon/mon.js +++ b/mon/mon.js @@ -317,8 +317,14 @@ class Mon ok(false); }, this.config.etcd_mon_timeout); this.ws = new WebSocket(base+'/watch'); + const fail = () => + { + ok(false); + }; + this.ws.on('error', fail); this.ws.on('open', () => { + this.ws.removeListener('error', fail); if (timer_id) clearTimeout(timer_id); ok(true); @@ -445,7 +451,7 @@ class Mon async get_lease() { const max_ttl = this.config.etcd_mon_ttl + this.config.etcd_mon_timeout/1000*this.config.etcd_mon_retries; - const res = await this.etcd_call('/lease/grant', { TTL: max_ttl }, this.config.etcd_mon_timeout, this.config.etcd_mon_retries); + const res = await this.etcd_call('/lease/grant', { TTL: max_ttl }, this.config.etcd_mon_timeout, -1); this.etcd_lease_id = res.ID; setInterval(async () => { @@ -1241,6 +1247,11 @@ class Mon console.error('etcd returned error: '+res.json.error); break; } + if (this.etcd_urls.length > 1) + { + // Stick to the same etcd for the rest of calls + this.etcd_urls = [ base ]; + } return res.json; } retry++;