flosse / json-file-store

A simple JSON store for Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Race condition.

ChangXiaoning opened this issue · comments

Hi, I think there is a race condition in your project: Since I want to store all objects in a single file, set the type option to single. Then, I have two non-blocking requests r1 and r2. r1 saves object o1 with id 1 and r2 deletes the object by id 1. json-file-store will prepare different this._cache to asynchronously write into file. Since two file writing are asynchronously executed, the content of the file is non-deterministic. In other words, it is non-deterministic whether is object with id 1 exists in the file. Maybe a better solution is to utilize a queue, which sequentializes multiple requests.