Skip to content

Commit

Permalink
Fix faulty pathExists race condition (SAP#2605)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndricimrr authored Mar 14, 2022
1 parent c734c8f commit f091955
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions client/src/linkManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {},
Expand All @@ -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)
);

Expand Down

0 comments on commit f091955

Please sign in to comment.