Skip to content

Commit

Permalink
Refresh cache before reading contents of bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
lettertwo committed Jul 5, 2023
1 parent c593971 commit 7f74f36
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/core/core/src/requests/WriteBundleRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type WriteBundleRequestInput = {|
bundle: Bundle,
info: BundleInfo,
hashRefToNameHash: Map<string, string>,
shouldResetReadCtx: boolean,
|};

type RunInput<TResult> = {|
Expand Down Expand Up @@ -129,6 +130,16 @@ async function run({input, options, api}) {
if (info.isLargeBlob) {
contentStream = options.cache.getStream(cacheKeys.content);
} else {
// Force a refresh of the cache to avoid a race condition
// between threaded reads and writes that can result in an LMDB cache miss:
// 1. Thread A has read some value from cache, necessitating a read transaction.
// 2. Concurrently, Thread B finishes a packaging request.
// 3. Subsequently, Thread A is tasked with this request, but fails because the read transaction is stale.
// This only occurs if the reading thread has a transaction that was created before the writing thread committed,
// and the transaction is still live when the reading thread attempts to get the written value.
// See https://github.com/parcel-bundler/parcel/issues/9121
options.cache.refresh();

contentStream = blobToStream(
await options.cache.getBlob(cacheKeys.content),
);
Expand Down

0 comments on commit 7f74f36

Please sign in to comment.