From 221e9e859cf2d7ea286e08017c09b87c04512fd5 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Tue, 12 Mar 2024 16:33:38 +0100 Subject: [PATCH] Potential fox to file reload race condition --- common/spaces/evented_space_primitives.ts | 14 ++++++++++---- web/client.ts | 1 - 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/common/spaces/evented_space_primitives.ts b/common/spaces/evented_space_primitives.ts index 339a3c7b..78141496 100644 --- a/common/spaces/evented_space_primitives.ts +++ b/common/spaces/evented_space_primitives.ts @@ -29,13 +29,19 @@ export class EventedSpacePrimitives implements SpacePrimitives { } async fetchFileList(): Promise { - const newFileList = await this.wrapped.fetchFileList(); if (this.alreadyFetching) { - // Avoid race conditions, let's just skip this in terms of event triggering: that's ok - return newFileList; + // Some other operation (read, write, list, meta) is already going on + // this will likely trigger events, so let's not worry about any of that and avoid race condition and inconsistent data. + console.info( + "alreadyFetching is on, skipping even triggering for fetchFileList.", + ); + return this.wrapped.fetchFileList(); } + // Fetching mutex + this.alreadyFetching = true; + // Fetch the list + const newFileList = await this.wrapped.fetchFileList(); try { - this.alreadyFetching = true; const deletedFiles = new Set(Object.keys(this.spaceSnapshot)); for (const meta of newFileList) { const oldHash = this.spaceSnapshot[meta.name]; diff --git a/web/client.ts b/web/client.ts index 63536330..438b3037 100644 --- a/web/client.ts +++ b/web/client.ts @@ -603,7 +603,6 @@ export class Client { if ( this.space.watchInterval && `${this.currentPage}.md` === path ) { - console.trace(); console.log( "Page changed elsewhere, reloading. Old hash", oldHash,