Restrictions to modifying request->headers_in.headers in NGX_HTTP_PREACCESS_PHASE?

Ryan Burn rnickb731 at gmail.com
Wed Mar 28 19:47:04 UTC 2018


Hi,

I have a module that registers a handler to run in
NGX_HTTP_PREACCESS_PHASE. The handler adds headers to
request->headers_in.headers. This works as I would expect most of the
time. But I am seeing cases of some crashes when calling

      ngx_list_push(&request->headers_in.headers));

Are there any restrictions where you are not allowed to push to
headers_in.headers like that in the preaccess phase?

This is the line that where the segfault is reported as happening:
https://github.com/opentracing-contrib/nginx-opentracing/blob/master/opentracing/src/inject_span_context.cpp#L23

And the backtrace (taken from
https://github.com/kubernetes/ingress-nginx/issues/2222#issue-306992059):

#0  0x0000561139f929ec in ngx_list_push ()
#1  0x00007f7a1adbb6ab in
ngx_opentracing::inject_span_context(opentracing::v1::Tracer const&,
ngx_http_request_s*, opentracing::v1::SpanContext const&) () from
/etc/nginx/modules/ngx_http_opentracing_module.so
#2  0x00007f7a1adbcf81 in
ngx_opentracing::OpenTracingRequestInstrumentor::OpenTracingRequestInstrumentor(ngx_http_request_s*,
ngx_http_core_loc_conf_s*, ngx_opentracing::opentracing_loc_conf_t*)
() from /etc/nginx/modules/ngx_http_opentracing_module.so
#3  0x00007f7a1adbdce6 in
ngx_opentracing::on_enter_block(ngx_http_request_s*) () from
/etc/nginx/modules/ngx_http_opentracing_module.so
#4  0x000056113a097a33 in ngx_http_core_generic_phase ()
#5  0x000056113a093645 in ngx_http_core_run_phases ()
#6  0x000056113a08f03e in ngx_http_process_request ()
#7  0x000056113a09068c in ngx_http_process_request_line ()
#8  0x000056113a0a6be1 in ngx_epoll_process_events.lto_priv ()
#9  0x000056113a0c45df in ngx_process_events_and_timers ()
#10 0x000056113a0a8405 in ngx_worker_process_cycle ()
#11 0x000056113a0be07f in ngx_spawn_process ()
#12 0x000056113a0a9715 in ngx_master_process_cycle ()
#13 0x0000561139f8a654 in main ()


More information about the nginx-devel mailing list