[FIX] bus: last bus subscription when switching offline/online

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 <ged@odoo.com>
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
tsm-odoo
2023-02-03 11:45:32 +01:00
parent df09c5c20f
commit d74057344d
@@ -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();
}