Nginx NJS fs.writeFileSync is atomic writing and race condition prevention ?
Dmitry Volyntsev
xeioex at nginx.com
Fri Oct 19 11:27:27 UTC 2018
On 19.10.2018 06:33, HENG wrote:
> Hello:
>
> I am new to Nginx NJS, and I want to write a website with NJS.
>
> I want to write a simple JSON database with NJS fs.writeFileSync ,just
> like Node.js LowDB.
>
> but I have no idea . Does NJS fs.writeFileSync is atomic writing and
> race condition prevention ?
http://hg.nginx.org/njs/file/tip/njs/njs_fs.c#l649
It simply opens the file, makes several write syscalls into it, and
closes the file.
So, it is not atomic.
Probably we need here something like
https://www.npmjs.com/package/write-file-atomic
>
> If NJS fs.writeFileSync is NOT atomic writing, it can NOT be treate as a
> normal database file write.
>
> Thank you !
>
> --
> --------------------------------------------------------------------
> Heng
> ---------------------------------------------------------------------
> --
>
>
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
>
More information about the nginx-devel
mailing list