-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
the set method is not concurrent access safe, because it's possible to read the cache files while they are being rewritten by a cache update request.
try {
await ensureDirExists(path.dirname(filename));
// you can read these files from an other green thread at the same time
await fs.writeFile(filename + ".data", compressedValue);
await fs.writeFile(filename + ".meta", JSON.stringify(metadata));
}
replace them with some atomic file system method, like rename:
try {
await ensureDirExists(path.dirname(filename));
const tmpdir = await fs.mkdtemp(path.dirname(filename));
await fs.writeFile(tmpdir + "/tmp.data", compressedValue);
await fs.writeFile(tmpdir + "/tmp.meta", JSON.stringify(metadata));
await fs.rename(tmpdir + "/tmp.data", filename + ".data");
await fs.rename(tmpdir + "/tmp.meta", filename + ".meta");
await fs.rmdir(tmpdir);
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels