From d74057344dbba58d9b232d5d201166c548bdb5e1 Mon Sep 17 00:00:00 2001 From: tsm-odoo Date: Mon, 30 Jan 2023 12:14:33 +0000 Subject: [PATCH] [FIX] bus: last bus subscription when switching offline/online MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, the bus worker would not subscribe to any channel if the `_start` method was called before the socket was closed after calling `_stop`. This is due to the fact that the close handler is supposed to clean the last subscription when the socket is closed. In this case, the handler is never called and the subscription is considered already doned which is not the case. closes odoo/odoo#111405 X-original-commit: 9e32c900e922674b4423407089cee58848ecdea1 Signed-off-by: Géry Debongnie Signed-off-by: Sébastien Theys (seb) --- addons/bus/static/src/workers/websocket_worker.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/bus/static/src/workers/websocket_worker.js b/addons/bus/static/src/workers/websocket_worker.js index 1a8d23cb9e3..e58a697619e 100644 --- a/addons/bus/static/src/workers/websocket_worker.js +++ b/addons/bus/static/src/workers/websocket_worker.js @@ -34,8 +34,9 @@ export const WEBSOCKET_CLOSE_CODES = Object.freeze({ }); // Should be incremented on every worker update in order to force // update of the worker in browser cache. -export const WORKER_VERSION = '1.0.2'; +export const WORKER_VERSION = '1.0.3'; const INITIAL_RECONNECT_DELAY = 1000; +const MAXIMUM_RECONNECT_DELAY = 60000; /** * This class regroups the logic necessary in order for the @@ -335,7 +336,7 @@ export class WebsocketWorker { * applied to the reconnect attempts. */ _retryConnectionWithDelay() { - this.connectRetryDelay = this.connectRetryDelay * 1.5 + 1000 * Math.random(); + this.connectRetryDelay = Math.min(this.connectRetryDelay * 1.5, MAXIMUM_RECONNECT_DELAY) + 1000 * Math.random(); this.connectTimeout = setTimeout(this._start.bind(this), this.connectRetryDelay); } @@ -376,6 +377,7 @@ export class WebsocketWorker { clearTimeout(this.connectTimeout); this.connectRetryDelay = INITIAL_RECONNECT_DELAY; this.isReconnecting = false; + this.lastChannelSubscription = null; if (this.websocket) { this.websocket.close(); }