<div>That`s right! I almost forgot that.</div><div><div><br></div><div><br></div><div style="font-size: 12px;font-family: Arial Narrow;padding:2px 0 2px 0;">------------------ Original ------------------</div><div style="font-size: 12px;background:#efefef;padding:8px;"><div><b>From: </b> "734819342";<734819342@qq.com>;</div><div><b>Send time:</b> Wednesday, Apr 19, 2017 10:23 AM</div><div><b>To:</b> "nginx-devel@nginx.org"<nginx-devel@nginx.org>; <wbr></div><div></div><div><b>Subject: </b> Re: crash in ngx_add_timer</div></div><div><br></div><div style="font:14px/1.5 'Lucida Grande', '微软雅黑';color:#333;"><p style="font:14px/1.5 'Consolas';margin:0;">Hi,</p><p style="font:14px/1.5 'Consolas';margin:0;"><br></p><p style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 14px; line-height: 1.5; margin: 0px;"><font face="Consolas">    U should not call ngx_add_timer there, cause </font><span style="font-family: Menlo, Monaco, 'Courier New', monospace; color: rgb(0, 0, 0); font-size: 12px; white-space: pre;">ngx_event_timer_rbtree is initialized in </span><span style="color: rgb(0, 0, 0); font-family: Menlo, Monaco, 'Courier New', monospace; font-size: 12px; white-space: pre;">[</span><span style="color: rgb(0, 128, 0); font-family: Menlo, Monaco, 'Courier New', monospace; font-size: 12px; white-space: pre;">init process</span><span style="color: rgb(0, 0, 0); font-family: Menlo, Monaco, 'Courier New', monospace; font-size: 12px; white-space: pre;">].</span></p><p style="font-style: normal; font-variant-caps: normal; font-weight: normal; font-size: 14px; line-height: 1.5; margin: 0px;"><span style="color: rgb(0, 0, 0); font-family: Menlo, Monaco, 'Courier New', monospace; font-size: 12px; white-space: pre;"><br></span></p><div><div style="font: 14px/1.5 'Lucida Grande';"><div class="" style="font-family: 'Lucida Grande', 'Lucida Sans Unicode', sans-serif !important;">----------------------------</div><div class="" style="font-family: 'Lucida Grande', 'Lucida Sans Unicode', sans-serif !important;"><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt; text-align: justify; line-height: 12pt;"><span class="" style="line-height: 21px; text-align: start;">Ben</span></p><div class="">best regards</div></div><div class="" style="font-family: 'Lucida Grande', 'Lucida Sans Unicode', sans-serif !important;"><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt 72pt; text-align: justify; line-height: 22px; text-indent: -72pt;"><br></p><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt 72pt; text-align: justify; line-height: 22px; text-indent: -72pt;"><u><span lang="EN-US" style="color: blue;"></span></u></p></div></div></div><span style="font: 14px/1.5 'Lucida Grande';color:#333;"><br></span><div class="foxmail_blockquote_fromhere_element" style="font: 12px/1.5 'Lucida Grande';padding:2px 0 2px 0;"><span style="color:#333;text-decoration:line-through;white-space:pre-wrap;">                            </span> Original Message <span style="color:#333;text-decoration:line-through;white-space:pre-wrap;">                            </span></div><div style="font: 12px/1.5 'Lucida Grande';background:#efefef;color:#666666;padding:8px;"><div><b style="color:#999;">Sender:</b> Dk Jack<dnj0496@gmail.com></div><div><b style="color:#999;">Recipient:</b> nginx-devel@nginx.org<nginx-devel@nginx.org></div><div><b style="color:#999;">Date:</b> Wednesday, Apr 19, 2017?10:03</div><div><b style="color:#999;">Subject:</b> Re: crash in ngx_add_timer</div></div><br><div class="mail_quote_336705954DA64C1C8B1F92A67113670B" style="font: 14px/1.5 'Lucida Grande';color:#333;">



<div>
<div dir="ltr">Hi,
<div>The crash is happening at line:
<div><br>
</div>
<div>ngx_add_timer(&ev2, 6);    // line 81<br>
</div>
<div><br>
</div>
<div>i.e. when it's trying to insert the second time. It doesn't even get to the handler.</div>
</div>
<div><br>
</div>
<div>What would be a good value to assign to ev->log? I added:</div>
<div><br>
</div>
<div>ev->log = cf->cycle->log</div>
<div><br>
</div>
<div>I am still getting the crash when I try to insert the second timer.</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Tue, Apr 18, 2017 at 6:53 PM, 胡聪 (hucc) <span dir="ltr">
<<a href="mailto:hucong.c@foxmail.com" target="_blank">hucong.c@foxmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>Hi,</div>
<div><br>
</div>
<div>At the first glance, the ev->log should be assigned a valid value.</div>
<div>
<div><br>
</div>
<div><br>
</div>
<div style="font-size:12px;font-family:Arial Narrow;padding:2px 0 2px 0">------------------ Original --<wbr>----------------</div>
<div style="font-size:12px;background:#efefef;padding:8px">
<div><b>From: </b> "Dk Jack";<<a href="mailto:dnj0496@gmail.com" target="_blank">dnj0496@gmail.com</a>>;</div>
<div><b>Send time:</b> Wednesday, Apr 19, 2017 8:23 AM</div>
<div><b>To:</b> "nginx-devel"<<a href="mailto:nginx-devel@nginx.org" target="_blank">nginx-devel@<wbr>nginx.org</a>>;
</div>
<div></div>
<div><b>Subject: </b> Re: crash in ngx_add_timer</div>
</div>
<div>
<div class="h5">
<div><br>
</div>
<div dir="ltr">resending since the attachment which had the code didn't make it...
<div><br>
</div>
<div>Dk.</div>
<div><br>
</div>
<div>
<div>#include <assert.h></div>
<div>#include <nginx.h></div>
<div>#include <ngx_config.h></div>
<div>#include <ngx_core.h></div>
<div>#include <ngx_http.h></div>
<div><br>
</div>
<div>static ngx_event_t ev1;</div>
<div>static ngx_event_t ev2;</div>
<div>static ngx_event_t ev3;</div>
<div><br>
</div>
<div>char ev1_data[] = "event1";</div>
<div>char ev2_data[] = "event2";</div>
<div>char ev3_data[] = "event3";</div>
<div><br>
</div>
<div>static ngx_int_t</div>
<div>ngx_test_handler(ngx_http_<wbr>request_t *r)</div>
<div>{</div>
<div>  if (r->main->internal) {</div>
<div>    return NGX_DECLINED;</div>
<div>  }</div>
<div><br>
</div>
<div>  r->main->internal = 1;</div>
<div><br>
</div>
<div>  ngx_table_elt_t *h;</div>
<div>  h = ngx_list_push(&r->headers_out.<wbr>headers);</div>
<div>  h->hash = 1;</div>
<div>  ngx_str_set(&h->key, "X-NGINX-Test");</div>
<div>  ngx_str_set(&h->value, "Hello World!");</div>
<div><br>
</div>
<div>  return NGX_DECLINED;</div>
<div>}</div>
<div><br>
</div>
<div>static void</div>
<div>ev1_handler(ngx_event_t* ev)</div>
<div>{</div>
<div>  ngx_log_error(NGX_LOG_ERR, ev->log, 0, "received event: %s", (char *) ev->data);</div>
<div>  ngx_add_timer(&ev1, 5);</div>
<div>}</div>
<div><br>
</div>
<div>static void</div>
<div>ev2_handler(ngx_event_t* ev)</div>
<div>{</div>
<div>  ngx_log_error(NGX_LOG_ERR, ev->log, 0, "received event: %s", (char *) ev->data);</div>
<div>  ngx_add_timer(&ev2, 6);</div>
<div>}</div>
<div><br>
</div>
<div>static void</div>
<div>ev3_handler(ngx_event_t* ev)</div>
<div>{</div>
<div>  ngx_log_error(NGX_LOG_ERR, ev->log, 0, "received event: %s", (char *) ev->data);</div>
<div>  ngx_add_timer(&ev3, 7);</div>
<div>}</div>
<div><br>
</div>
<div>static ngx_int_t</div>
<div>ngx_test_init (ngx_conf_t *cf)</div>
<div>{</div>
<div>  ngx_http_handler_pt *h;</div>
<div>  ngx_http_core_main_conf_t *cmcf;</div>
<div><br>
</div>
<div>  cmcf = ngx_http_conf_get_module_main_<wbr>conf(cf, ngx_http_core_module);</div>
<div>  h = ngx_array_push(&cmcf->phases[<wbr>NGX_HTTP_ACCESS_PHASE].<wbr>handlers);</div>
<div><br>
</div>
<div>  if (h == NULL) {</div>
<div>    ngx_log_error(NGX_LOG_ERR, cf->log, 0, "Cannot retrieve Nginx access handler pointer");</div>
<div>    return NGX_ERROR;</div>
<div>  }</div>
<div><br>
</div>
<div>  *h = ngx_test_handler;</div>
<div>  ngx_log_error(NGX_LOG_INFO, cf->log, 0, "[test] Installed test handler");</div>
<div><br>
</div>
<div>  ev1.handler = ev1_handler;</div>
<div>  ev1.data = ev1_data;</div>
<div><br>
</div>
<div>  ev2.handler = ev2_handler;</div>
<div>  ev2.data = ev2_data;</div>
<div><br>
</div>
<div>  ev3.handler = ev3_handler;</div>
<div>  ev3.data = ev3_data;</div>
<div><br>
</div>
<div>  ngx_add_timer(&ev1, 5);</div>
<div>  ngx_add_timer(&ev2, 6);</div>
<div>  ngx_add_timer(&ev3, 7);</div>
<div><br>
</div>
<div>  return NGX_OK;</div>
<div>}</div>
<div><br>
</div>
<div>static char *</div>
<div>parse_test_configuration (ngx_conf_t *cf, ngx_command_t *cmd, void *conf)</div>
<div>{</div>
<div>  ngx_str_t *value;</div>
<div><br>
</div>
<div>  if (cf->args->nelts != 2) {</div>
<div>    ngx_log_error(NGX_LOG_ERR, cf->log, 0</div>
<div>                  , "[ss-config] invalid params for config_file. Expected 2 received %d"</div>
<div>                  , cf->args->nelts);</div>
<div>    return NGX_CONF_ERROR;</div>
<div>  }</div>
<div><br>
</div>
<div>  value = cf->args->elts;</div>
<div><br>
</div>
<div>  ngx_log_error(NGX_LOG_ERR, cf->log, 0, "file-path: %V", &value[1]);</div>
<div><br>
</div>
<div>  return NGX_CONF_OK;</div>
<div>}</div>
<div><br>
</div>
<div><br>
</div>
<div>static ngx_http_module_t ngx_test_module_ctx = {</div>
<div>  NULL,                                 /* preconfiguration */</div>
<div>  ngx_test_init,              <span class="m_-1900769087749238231gmail-Apple-tab-span" style="white-space:pre-wrap">
</span>/* postconfiguration */</div>
<div>  NULL,                                 /* create main configuration */</div>
<div>  NULL,                                 /* init main configuration */</div>
<div>  NULL,                                 /* create server configuration */</div>
<div>  NULL,                                 /* merge server configuration */</div>
<div>  NULL,       <span class="m_-1900769087749238231gmail-Apple-tab-span" style="white-space:pre-wrap">
</span>/* create location configuration */</div>
<div>  NULL         <span class="m_-1900769087749238231gmail-Apple-tab-span" style="white-space:pre-wrap">
</span>/* merge location configuration */</div>
<div>};</div>
<div><br>
</div>
<div>static ngx_command_t ngx_test_module_cmds[] = {</div>
<div>  {</div>
<div>    ngx_string("config_file"),</div>
<div>    NGX_HTTP_MAIN_CONF|NGX_CONF_<wbr>TAKE1,</div>
<div>    parse_test_configuration,</div>
<div>    0,</div>
<div>    0,</div>
<div>    NULL</div>
<div>  }</div>
<div>  , ngx_null_command</div>
<div>};</div>
<div><br>
</div>
<div>ngx_module_t nginx_test_module = {</div>
<div>  NGX_MODULE_V1,</div>
<div>  &ngx_test_module_ctx,  <span class="m_-1900769087749238231gmail-Apple-tab-span" style="white-space:pre-wrap">
</span>/* module context */</div>
<div>  ngx_test_module_cmds,  <span class="m_-1900769087749238231gmail-Apple-tab-span" style="white-space:pre-wrap">
</span>/* module directives */</div>
<div>  NGX_HTTP_MODULE,                 /* module type */</div>
<div>  NULL,                            /* init master */</div>
<div>  NULL,                            /* init module */</div>
<div>  NULL,                            /* init process */</div>
<div>  NULL,                            /* init thread */</div>
<div>  NULL,                            /* exit thread */</div>
<div>  NULL,                            /* exit process */</div>
<div>  NULL,                            /* exit master */</div>
<div>  NGX_MODULE_V1_PADDING</div>
<div>};</div>
<div><br>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Tue, Apr 18, 2017 at 5:12 PM, Dk Jack <span dir="ltr">
<<a href="mailto:dnj0496@gmail.com" target="_blank">dnj0496@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<div dir="ltr">Hi,
<div>I am new to NGinx modules and I trying to write an nginx module. I am having an issue</div>
<div>where my module crashes when adding multiple timers. The first timer adds fine.</div>
<div>However, when I go to add the second timer, it crashes. I've simplified the code to a very</div>
<div>basic module (which is attached to this email). The backtrace is provided as well.</div>
<div>Do I need to do some sort of initialization before I add multiple timers. Any advice/help</div>
<div>is appreciated. Thanks.</div>
<div><br>
</div>
<div>Dk.</div>
<div><br>
</div>
<div>
<div><font face="monospace, monospace">Program received signal SIGSEGV, Segmentation fault.</font></div>
<div><font face="monospace, monospace">0x0000000000000000 in ?? ()</font></div>
<div><font face="monospace, monospace">(gdb) bt</font></div>
<div><font face="monospace, monospace">#0  0x0000000000000000 in ?? ()</font></div>
<div><font face="monospace, monospace">#1  0x000000000040d68b in ngx_rbtree_insert (tree=0x69dda0 <ngx_event_timer_rbtree>,</font></div>
<div><font face="monospace, monospace">    node=node@entry=0x69db08 <ev2+40>) at src/core/ngx_rbtree.c:44</font></div>
<div><font face="monospace, monospace">#2  0x000000000046ceb2 in ngx_event_add_timer (timer=6, ev=0x69dae0 <ev2>)</font></div>
<div><font face="monospace, monospace">    at src/event/ngx_event_timer.h:84</font></div>
<div><font face="monospace, monospace">#3  ngx_test_init (cf=<optimized out>)</font></div>
<div><font face="monospace, monospace">    at /home/ubuntu/git/mitigator/ngi<wbr>nx/build/../modules/nginx_miti<wbr>gator_module/platform/nginx-<wbr>test-module.c:81</font></div>
<div><font face="monospace, monospace">#4  0x0000000000424e83 in ngx_http_block (cf=0x7fffffffe0a0, cmd=<optimized out>,</font></div>
<div><font face="monospace, monospace">    conf=<optimized out>) at src/http/ngx_http.c:315</font></div>
<div><font face="monospace, monospace">#5  0x000000000041446b in ngx_conf_handler (last=1, cf=0x7fffffffe0a0)</font></div>
<div><font face="monospace, monospace">    at src/core/ngx_conf_file.c:427</font></div>
<div><font face="monospace, monospace">#6  ngx_conf_parse (cf=cf@entry=0x7fffffffe0a0, filename=filename@entry=0x6ad5<wbr>70)</font></div>
<div><font face="monospace, monospace">    at src/core/ngx_conf_file.c:283</font></div>
<div><font face="monospace, monospace">#7  0x0000000000411e1a in ngx_init_cycle (old_cycle=old_cycle@entry=0x7<wbr>fffffffe260)</font></div>
<div><font face="monospace, monospace">    at src/core/ngx_cycle.c:268</font></div>
<div><font face="monospace, monospace">#8  0x0000000000404208 in main (argc=<optimized out>, argv=<optimized out>) at src/core/nginx.c:268</font></div>
<div><font face="monospace, monospace">(gdb)</font></div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
______________________________<wbr>_________________<br>
nginx-devel mailing list<br>
<a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" rel="noreferrer" target="_blank">http://mailman.nginx.org/<wbr>mailman/listinfo/nginx-devel</a><br>
</blockquote>
</div>
<br>
</div>
</div>
</div>

</div></div></div>