[nginx] unnormal pid file

洪志道 hongzhidao at gmail.com
Sat Mar 18 07:43:36 UTC 2017


Hi.

It's easy to reproduce such problem that
the master/worker process are running without the pid file.

Step by step:

1. Start master process.
    > ./objs/nginx
    nginx.pid successfully create with content (23234)

2. Create an active connection, purpose for prevent previous master exit.
   > telnet 127.1 80

3. Quit the previous master, and it still alive for a while.
   > kill -QUIT 23234

4. Start new master process 23361, and the content of nginx.pid is changed
to 23361
   > ./objs/nginx
   It successfully start because of the listening port is closed by the
step 3.

5. Wait for a while, and the nginx.pid is deleted while the old master
process (23234) completely quit.

Now the master process (23361) is running without nginx.pid.

So, there are two key points:
1. Master start, I think there is not problem.
2. Master Exit, is it better to add the pid check with the pid file?

Anyway, I think we should guarantee the pid file associates with the
running process.

src/os/unix/ngx_process_cycle.c

+static ngx_int_t
+ngx_is_same_pid(ngx_cycle_t *cycle)
+{
+        return read_pid_from_pidfile. // TODO
+}

static void
ngx_master_process_exit(ngx_cycle_t *cycle)
{
    ngx_uint_t  i;

-   ngx_delete_pidfile(cycle);
+  if (ngx_is_same_pid(cycle)) {
+        ngx_delete_pidfile(cycle);
+
+  } else {
+        ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "blalala...");
+ }

Thanks.
B.R.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20170318/2e871205/attachment.html>


More information about the nginx-devel mailing list