open-telemetry / open-telemetry/opentelemetry-cpp-contrib
Nginx worker thread dies in internal requests
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 153
- Forks
- 184
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 26
Description
Describe your environment
- OpenTelemetry C++ 1.2.0
- OpenTelemetry C++ Contrib at 3808bc3be386fbcc58d39cd858fb375d7e1fafa3
- Nginx 1.19.9
I haven't narrowed down how to reproduce the issue yet but I'm getting a segfault in the code that was added in #94. Looks like the insert call on line 402 is bad. :(
#0 0x00007f7aa2425d6a in std::_Hashtable<ngx_http_request_s*, std::pair<ngx_http_request_s* const, TraceContext*>, std::allocator<std::pair<ngx_http_request_s* const, TraceContext*> >, std::__detail::_Select1st, std::equal_to<ngx_http_request_s*>, std::hash<ngx_http_request_s*>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::_M_bucket_index (this=0x0, __k=@0x7f7a968c5cb8: 0x7f7a9e3aaa30, __c=140164617382448) at /usr/include/c++/10.3.1/bits/hashtable.h:714
#1 0x00007f7aa2425f81 in std::_Hashtable<ngx_http_request_s*, std::pair<ngx_http_request_s* const, TraceContext*>, std::allocator<std::pair<ngx_http_request_s* const, TraceContext*> >, std::__detail::_Select1st, std::equal_to<ngx_http_request_s*>, std::hash<ngx_http_request_s*>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::_M_emplace<std::pair<ngx_http_request_s* const, TraceContext*> > (this=0x0) at /usr/include/c++/10.3.1/bits/hashtable.h:1711
#2 0x00007f7aa241eefa in std::__detail::_Insert<ngx_http_request_s*, std::pair<ngx_http_request_s* const, TraceContext*>, std::allocator<std::pair<ngx_http_request_s* const, TraceContext*> >, std::__detail::_Select1st, std::equal_to<ngx_http_request_s*>, std::hash<ngx_http_request_s*>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true>, false>::insert<std::pair<ngx_http_request_s* const, TraceContext*>, void> (this=0x0, __v=...) at /usr/include/c++/10.3.1/bits/hashtable_policy.h:1021
#3 0x00007f7aa2418cac in std::unordered_map<ngx_http_request_s*, TraceContext*, std::hash<ngx_http_request_s*>, std::equal_to<ngx_http_request_s*>, std::allocator<std::pair<ngx_http_request_s* const, TraceContext*> > >::insert (this=0x0, __x=...) at /usr/include/c++/10.3.1/bits/unordered_map.h:587
#4 0x00007f7aa240c6cb in CreateTraceContext (req=0x7f7a9e3aaa30, val=0x7f7a968ee240) at /opentelemetry-cpp-contrib/instrumentation/nginx/src/otel_ngx_module.cpp:402
#5 0x00007f7aa240c7c5 in StartNgxSpan (req=0x7f7a9e3aaa30) at /opentelemetry-cpp-contrib/instrumentation/nginx/src/otel_ngx_module.cpp:418
#6 0x000055ed6f3beac5 in ngx_http_core_rewrite_phase (r=0x7f7a9e3aaa30, ph=0x7f7a9e6a3088) at src/http/ngx_http_core_module.c:922
#7 0x000055ed6f3b9d49 in ngx_http_core_run_phases (r=0x7f7a9e3aaa30) at src/http/ngx_http_core_module.c:868
#8 0x000055ed6f3b9e1a in ngx_http_handler (r=<optimized out>) at src/http/ngx_http_core_module.c:851
#9 0x000055ed6f3c3a2c in ngx_http_run_posted_requests (c=c@entry=0x7f7a97434298) at src/http/ngx_http_request.c:2435
#10 0x000055ed6f3c6ebe in ngx_http_process_request_headers (rev=rev@entry=0x7f7a972b2670) at src/http/ngx_http_request.c:1529
#11 0x000055ed6f3c72b2 in ngx_http_process_request_line (rev=rev@entry=0x7f7a972b2670) at src/http/ngx_http_request.c:1175
#12 0x000055ed6f3c74e1 in ngx_http_wait_request_handler (rev=0x7f7a972b2670) at src/http/ngx_http_request.c:503
#13 0x000055ed6f3c78f9 in ngx_http_ssl_handshake_handler (c=0x7f7a97434298) at src/http/ngx_http_request.c:848
#14 0x000055ed6f3aeaa4 in ngx_ssl_handshake_handler (ev=0x7f7a972b2670) at src/event/ngx_event_openssl.c:2095
#15 0x000055ed6f3a9103 in ngx_epoll_process_events (cycle=0x7f7aa2cc8580, timer=<optimized out>, flags=<optimized out>) at src/event/modules/ngx_epoll_module.c:901
#16 0x000055ed6f39c140 in ngx_process_events_and_timers (cycle=cycle@entry=0x7f7aa2cc8580) at src/event/ngx_event.c:257
#17 0x000055ed6f3a67c8 in ngx_worker_process_cycle (cycle=0x7f7aa2cc8580, data=<optimized out>) at src/os/unix/ngx_process_cycle.c:753
#18 0x000055ed6f3a4850 in ngx_spawn_process (cycle=cycle@entry=0x7f7aa2cc8580, proc=proc@entry=0x55ed6f3a66bf <ngx_worker_process_cycle>, data=data@entry=0x0, name=name@entry=0x55ed6f4cbf97 "worker process",
respawn=respawn@entry=-4) at src/os/unix/ngx_process.c:199
#19 0x000055ed6f3a549e in ngx_start_worker_processes (cycle=cycle@entry=0x7f7aa2cc8580, n=8, type=type@entry=-4) at src/os/unix/ngx_process_cycle.c:373
#20 0x000055ed6f3a7369 in ngx_master_process_cycle (cycle=0x7f7aa2cc8580, cycle@entry=0x7f7aa2ccd210) at src/os/unix/ngx_process_cycle.c:234
#21 0x000055ed6f379af9 in main (argc=<optimized out>, argv=<optimized out>) at src/core/nginx.c:386
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in instrumentation/nginx/src/otel_ngx_module.cpp around CreateTraceContext at lines 384-404 and its caller StartNgxSpan at line 418. Investigate the reported crash in the unordered_map insert during internal requests, first establishing a reproducible Nginx worker failure with the listed OpenTelemetry and Nginx versions. Done means the worker no longer segfaults in this path and the behavior is verified against the reported stack trace.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, nginx
- Domain
- backend, observability
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100