FluidFramework icon indicating copy to clipboard operation
FluidFramework copied to clipboard

Routerlicious driver does not await blobsShaCache sets

Open arinwt opened this issue 6 years ago • 1 comments

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:

  1. Blob 1 check if hash in cache (false), then await createBlob
  2. Blob 2 check if hash in cache (false), then await createBlob
  3. Blob 1 add hash to cache
  4. Blob 2 add hash to cache

One solution is to store a Promise (maybe of type boolean?) as value of map before calling await.

arinwt avatar Feb 20 '20 01:02 arinwt

https://github.com/microsoft/FluidFramework/pull/2047

jatgarg avatar May 06 '20 00:05 jatgarg