Potential fox to file reload race condition

pull/770/head^2
Zef Hemel 2024-03-12 16:33:38 +01:00
parent 34af1b1bb6
commit 221e9e859c
2 changed files with 10 additions and 5 deletions

View File

@ -29,13 +29,19 @@ export class EventedSpacePrimitives implements SpacePrimitives {
}
async fetchFileList(): Promise<FileMeta[]> {
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<string>(Object.keys(this.spaceSnapshot));
for (const meta of newFileList) {
const oldHash = this.spaceSnapshot[meta.name];

View File

@ -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,