NGX error logging - Race condition possible?

Igor Sysoev igor at sysoev.ru
Mon Sep 3 06:14:30 UTC 2018


> On 2 Sep 2018, at 21:44, Slawitscheck Stefan via nginx-devel <nginx-devel at nginx.org> wrote:
> 
> Dear Development Team,
> 
> I have one question about the logging mechanism of nginx with more worker processes under Windows.
> 
> In ngx_log.c is the function ngx_write_console() which calls the systemcall WriteFile().
> 
> How is do you ensures that there is no race condition while using this function to write into the error.log file with multiple working processes?
> 
> From my understanding, each worker process writes into the error.log file by itself. So it could be that there are two processes (worker) trying to write at the same time?
> So usually you need some locking, semaphore, mutex or something like that?
> 
> If you ensure that there will be no race condition, how do you guarantee it?
> 
> I am looking forward to your answer.

It should be guaranteed by CreateFile options: FILE_APPEND_DATA | SYNCHRONIZE.


-- 
Igor Sysoev
http://nginx.com



More information about the nginx-devel mailing list