Skip to content

Commit

Permalink
fix : Synchronize read and writes to avoid race condition reading tra…
Browse files Browse the repository at this point in the history
…nspiled files from disk cache

First add a maker file to check if the previous write was fully completed. Then again in writefile section change the write mode to wx which uses exclusive lock and if two writes happen same time and we get EEXist error then ignore that
FIX for microsoft#30577
  • Loading branch information
sunilsurana committed Apr 27, 2024
1 parent 733ee09 commit 91d87ed
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/playwright/src/transform/compilationCache.ts
Expand Up @@ -148,11 +148,10 @@ export function getFromCompilationCache(filename: string, hash: string, moduleUr
fs.writeFileSync(dataPath, JSON.stringify(Object.fromEntries(data.entries()), undefined, 2), { encoding: 'utf8', flag: 'wx' });
fs.writeFileSync(codePath, code, 'utf8');
fs.closeSync(fs.openSync(markerFile, 'wx'));
}
catch (error) {
} catch (error) {
if (error.code === 'EEXIST') {
} else {
throw error;
throw error;
}
}
const serializedCache = _innerAddToCompilationCacheAndSerialize(filename, { codePath, sourceMapPath, dataPath, moduleUrl });
Expand Down

0 comments on commit 91d87ed

Please sign in to comment.