Opened 9 years ago

Closed 9 years ago

Last modified 6 years ago

#945 closed defect (wontfix)

when setting master_process off, nginx segmentation fault when sent mutiple HUP singals

Reported by: tianchaijz@… Owned by:
Priority: minor Milestone:
Component: documentation Version: 1.9.x
Keywords: Cc:
uname -a:
nginx -V: nginx version: nginx/1.9.13
built by gcc 5.3.0 (GCC)
configure arguments: --prefix=/tmp/nginx

Description

A simple configuration is shown below:

worker_processes  1;
master_process off;
daemon         off;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile           on;
    keepalive_timeout  65;

    server {
        listen       1200;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }
    }
}

After starting nginx process, send multiple HUP signals to it, it will segmentation fault:

watch -n 1 'kill -HUP PID'

After inspecting the core, I found the code dereference a NULL pointer which leads the process segmentation fault:

(gdb) frame
#0  0x00000000004194e7 in ngx_clean_old_cycles (ev=0x6a5c00 <ngx_cleaner_event>) at src/core/ngx_cycle.c:1313
1313                if (cycle[i]->connections[n].fd != (ngx_socket_t) -1) {
(gdb) bt
#0  0x00000000004194e7 in ngx_clean_old_cycles (ev=0x6a5c00 <ngx_cleaner_event>) at src/core/ngx_cycle.c:1313
#1  0x0000000000425f09 in ngx_event_expire_timers () at src/event/ngx_event_timer.c:94
#2  0x0000000000425b87 in ngx_process_events_and_timers (cycle=cycle@entry=0x1687010) at src/event/ngx_event.c:256
#3  0x000000000042ca91 in ngx_single_process_cycle (cycle=0x1687010, cycle@entry=0x138f480) at src/os/unix/ngx_process_cycle.c:309
#4  0x000000000040c615 in main (argc=<optimized out>, argv=<optimized out>) at src/core/nginx.c:364
(gdb) p i
$10 = 1
(gdb) p n
$11 = 0
(gdb) p cycle[1]->connections[0]
Cannot access memory at address 0x0
(gdb) p cycle[1]->connections
$12 = (ngx_connection_t *) 0x0
(gdb)
nginx version: nginx/1.9.13
built by gcc 5.3.0 (GCC)
configure arguments: --prefix=/tmp/nginx

Linux tianchaijz 4.4.3-1 #12 SMP PREEMPT Sun Feb 28 17:55:31 CST 2016 x86_64 GNU/Linux

Change History (6)

comment:1 by Maxim Dounin, 9 years ago

Resolution: wontfix
Status: newclosed

The master_process directive is only expected to be used for development. Avoid using it unless you understand what you are doing and associated limitations. As of now nginx doesn't survive configuration reloads without separate master process, it simply doesn't work and leaves nginx in an inconsistent state, with segfault expected sooner or later.

comment:2 by tianchaijz@…, 9 years ago

Thanks!

One more question, why not ignore the HUP signal when there is no master process rather than leave the nginx process in an inconsistent state?

Version 0, edited 9 years ago by tianchaijz@… (next)

comment:3 by Maxim Dounin, 9 years ago

There are no reasons to ignore configuration reloads without a master process as they shouldn't happen except during nginx development in the first place. And because there are already parts which work, and probably at some point configuration reloads will be fully working even when there is no master process.

comment:4 by tianchaijz@…, 9 years ago

Thank you again :)

comment:5 by Maxim Dounin, 8 years ago

See also #1251.

comment:6 by Maxim Dounin, 6 years ago

See also #1563.

Note: See TracTickets for help on using tickets.