Skip to content

session's .save() is not thread-safe #1

@TheSynus

Description

@TheSynus

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions