It seems as if the save() function of the session is not thread-safe.
When the same user invokes
data.session.save(sessionData);
multiple times in a really short time frame, the session file is getting corrupted.
A hacky and easy solution would be to simply use the blocking function to write a file
fs.writeFileSync(fullPath, content, options);
|
await fsp.writeFile(fullPath, content, options) |
Otherwise you need to emulate some kind of lock, maybe create a map of pending write promises({[path: string]: Promise<void> | undefined}) and wait if there is already a promise or completely lock the whole function with https://www.npmjs.com/package/async-lock
It seems as if the
save()function of thesessionis not thread-safe.When the same user invokes
data.session.save(sessionData);multiple times in a really short time frame, the session file is getting corrupted.
A hacky and easy solution would be to simply use the blocking function to write a file
fs.writeFileSync(fullPath, content, options);buzzy/src/application/filesystem-utils/file.ts
Line 133 in af5666d
Otherwise you need to emulate some kind of
lock, maybe create a map of pending write promises({[path: string]: Promise<void> | undefined}) and wait if there is already a promise or completely lock the whole function with https://www.npmjs.com/package/async-lock