[FIX] bus: fix websocket outdated on db change
When the bus service is loaded, it connects to the websocket worker and passes some information that are used to determine whether the websocket connection is outdated. Amongst them, the user id is used to detect when the user changed and when the websocket connection should be refreshed. This is not enough to ensure the websocket connection is still relevant: the user id could be the same but the db could have changed. The websocket would then be linked to the previous database. This commit fixes the issue by sending the db name alongside the user id. This will ensure the connection is refreshed when it is outdated. Steps to reproduce the issue: - Log in on db1 on 2 tabs - Log out - Log in on db2 - Try to star a message in the discuss app - Nothing happens, the messages are sent from db2 but the socket listens to db1 closes odoo/odoo#141263 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
@@ -98,6 +98,7 @@ export const busService = {
|
||||
}
|
||||
send("initialize_connection", {
|
||||
websocketURL: `${params.serverURL.replace("http", "ws")}/websocket`,
|
||||
db: session.db,
|
||||
debug: odoo.debug,
|
||||
lastNotificationId: multiTab.getSharedValue("last_notification_id", 0),
|
||||
uid,
|
||||
|
||||
@@ -53,6 +53,7 @@ export class WebsocketWorker {
|
||||
this.newestStartTs = undefined;
|
||||
this.websocketURL = "";
|
||||
this.currentUID = null;
|
||||
this.currentDB = null;
|
||||
this.isWaitingForNewUID = true;
|
||||
this.channelsByClient = new Map();
|
||||
this.connectRetryDelay = this.INITIAL_RECONNECT_DELAY;
|
||||
@@ -216,6 +217,7 @@ export class WebsocketWorker {
|
||||
* Initialize a client connection to this worker.
|
||||
*
|
||||
* @param {Object} param0
|
||||
* @param {string} [param0.db] Database name.
|
||||
* @param {String} [param0.debug] Current debugging mode for the
|
||||
* given client.
|
||||
* @param {Number} [param0.lastNotificationId] Last notification id
|
||||
@@ -227,7 +229,7 @@ export class WebsocketWorker {
|
||||
* - undefined: not available (e.g. livechat support page)
|
||||
* @param {Number} param0.startTs Timestamp of start of bus service sender.
|
||||
*/
|
||||
_initializeConnection(client, { debug, lastNotificationId, uid, websocketURL, startTs }) {
|
||||
_initializeConnection(client, { db, debug, lastNotificationId, uid, websocketURL, startTs }) {
|
||||
if (this.newestStartTs && this.newestStartTs > startTs) {
|
||||
this.debugModeByClient[client] = debug;
|
||||
this.isDebug = Object.values(this.debugModeByClient).some(
|
||||
@@ -248,8 +250,9 @@ export class WebsocketWorker {
|
||||
this.isWaitingForNewUID = false;
|
||||
this.currentUID = uid;
|
||||
}
|
||||
if (this.currentUID !== uid && isCurrentUserKnown) {
|
||||
if ((this.currentUID !== uid && isCurrentUserKnown) || this.currentDB !== db) {
|
||||
this.currentUID = uid;
|
||||
this.currentDB = db;
|
||||
if (this.websocket) {
|
||||
this.websocket.close(WEBSOCKET_CLOSE_CODES.CLEAN);
|
||||
}
|
||||
@@ -390,7 +393,8 @@ export class WebsocketWorker {
|
||||
*/
|
||||
_retryConnectionWithDelay() {
|
||||
this.connectRetryDelay =
|
||||
Math.min(this.connectRetryDelay * 1.5, MAXIMUM_RECONNECT_DELAY) + this.RECONNECT_JITTER * Math.random();
|
||||
Math.min(this.connectRetryDelay * 1.5, MAXIMUM_RECONNECT_DELAY) +
|
||||
this.RECONNECT_JITTER * Math.random();
|
||||
this.connectTimeout = setTimeout(this._start.bind(this), this.connectRetryDelay);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user