Re: Nginx NJS fs.writeFileSync is atomic writing and race condition prevention ?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: Nginx NJS fs.writeFileSync is atomic writing and race condition prevention ?

Dmitry Volyntsev


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
> [hidden email]
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
>
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx