From f0919551e3b2e70299d8762769dfbfbe8194b77b Mon Sep 17 00:00:00 2001 From: Ndricim Rrapi Date: Mon, 14 Mar 2022 14:07:02 +0100 Subject: [PATCH] Fix faulty pathExists race condition (#2605) --- client/src/linkManager.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/client/src/linkManager.js b/client/src/linkManager.js index bfc04926a9..676e91634c 100644 --- a/client/src/linkManager.js +++ b/client/src/linkManager.js @@ -290,7 +290,7 @@ export class linkManager extends LuigiClientBase { * ); */ pathExists(path) { - const currentId = Date.now(); + const currentId = helpers.getRandomId(); const pathExistsPromises = this.getPromise('pathExistsPromises') || {}; pathExistsPromises[currentId] = { resolveFn: function() {}, @@ -306,12 +306,14 @@ export class linkManager extends LuigiClientBase { function(e, listenerId) { const data = e.data.data; const pathExistsPromises = this.getPromise('pathExistsPromises') || {}; - if (pathExistsPromises[data.correlationId]) { - pathExistsPromises[data.correlationId].resolveFn(data.pathExists); - delete pathExistsPromises[data.correlationId]; - this.setPromise('pathExistsPromises', pathExistsPromises); + if (data.correlationId === currentId) { + if (pathExistsPromises[data.correlationId]) { + pathExistsPromises[data.correlationId].resolveFn(data.pathExists); + delete pathExistsPromises[data.correlationId]; + this.setPromise('pathExistsPromises', pathExistsPromises); + } + helpers.removeEventListener(listenerId); } - helpers.removeEventListener(listenerId); }.bind(this) );