FluidFramework
FluidFramework copied to clipboard
Routerlicious driver does not await blobsShaCache sets
const hash = gitHashFile(Buffer.from(content, encoding));
if (!this.blobsShaCache.has(hash)) {
const blob = await this.manager.createBlob(content, encoding);
this.blobsShaCache.set(blob.sha, "");
}
Because the code above is async, the 2nd line to check if the hash is already in the cache may occur before the previous one actually calls set (line 4), because of the await in line 3.
So for example with 2 identical blobs, the execution may happen like so:
- Blob 1 check if hash in cache (false), then await
createBlob - Blob 2 check if hash in cache (false), then await
createBlob - Blob 1 add hash to cache
- Blob 2 add hash to cache
One solution is to store a Promise (maybe of type boolean?) as value of map before calling await.
https://github.com/microsoft/FluidFramework/pull/2047