Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sometimes occur "Segmentation fault". #851

Closed
ota-akira opened this issue Aug 18, 2020 · 11 comments
Closed

Sometimes occur "Segmentation fault". #851

ota-akira opened this issue Aug 18, 2020 · 11 comments

Comments

@ota-akira
Copy link

Describe the bug

Hi! I'm testing my application with elastic apm.
but I faced to SEGV on my application, it occurred from elastic-apm gem.
It not reproduce, sometimes occurred.

NOTE:
my application, APM Server not responding in time, terminating request error is acceptable, but SEGV is not acceptable.

Steps to reproduce

Expected behavior

Environment

  • OS: Linux (CentOS)
  • Ruby version: 2.5.3p105
  • Framework and version: Rails 5.2.4.3
  • APM Server version: 7.5.2-1 (rpm package)
  • Agent version: 3.8.0

I have 15 application servers, but apm server is 1 server. (because currently testing)

Additional context

Add any other context about the problem here.

  • Agent config options
Click to expand
server_url:  http://apm-server:8200
service_name: 'my app'
log_path: 'log/elastic_apm.log'
disable_send: false
disable_instrumentations:
  - delayed_job
  - json
  - mongo
  - sequel
  - sidekiq
  - sinatra
filter_exception_types:
  - ActiveRecord::RecordNotFound
  - ActiveHash::RecordNotFound
  - ActionController::UnknownHttpMethod
  - ActionController::RoutingError
  • backtrace log in my unicorn.log. (full size backtrace is very large, I paste only basic information)
Click to expand
/srv/app/shared/bundle/ruby/2.5.0/gems/elastic-apm-3.8.0/lib/elastic_apm/transport/base.rb:83: [BUG] Segmentation fault at 0x000055de00000050
ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0030 p:---- s:0148 e:000147 CFUNC  :push
c:0029 p:0045 s:0142 e:000141 METHOD /srv/app/shared/bundle/ruby/2.5.0/gems/elastic-apm-3.8.0/lib/elastic_apm/transport/base.rb:83
c:0028 p:0009 s:0136 e:000135 METHOD /srv/app/shared/bundle/ruby/2.5.0/gems/elastic-apm-3.8.0/lib/elastic_apm/agent.rb:147
c:0027 p:0007 s:0131 e:000130 BLOCK  /srv/app/shared/bundle/ruby/2.5.0/gems/elastic-apm-3.8.0/lib/elastic_apm/agent.rb:86 [FINISH]
c:0026 p:0010 s:0127 e:000126 BLOCK  /srv/app/shared/bundle/ruby/2.5.0/gems/elastic-apm-3.8.0/lib/elastic_apm/metrics.rb:116 [FINISH]
c:0025 p:---- s:0123 e:000122 CFUNC  :each
c:0024 p:0028 s:0119 e:000118 METHOD /srv/app/shared/bundle/ruby/2.5.0/gems/elastic-apm-3.8.0/lib/elastic_apm/metrics.rb:115
c:0023 p:0012 s:0114 e:000113 BLOCK  /srv/app/shared/bundle/ruby/2.5.0/gems/elastic-apm-3.8.0/lib/elastic_apm/metrics.rb:70 [FINISH]
c:0022 p:0021 s:0110 e:000109 BLOCK  /srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/safe_task_exe
c:0021 p:0003 s:0103 e:000102 BLOCK  /srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/synchronization/mutex_ [FINISH]
c:0020 p:---- s:0100 e:000099 CFUNC  :synchronize
c:0019 p:0018 s:0096 e:000095 METHOD /srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/synchronization/mutex_
c:0018 p:0005 s:0092 e:000091 METHOD /srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/safe_task_exe
c:0017 p:0043 s:0087 e:000086 METHOD /srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/timer_task.rb:312 [FINISH]
c:0016 p:---- s:0078 e:000077 IFUNC 
c:0015 p:0021 s:0075 e:000074 BLOCK  /srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/safe_task_exe
c:0014 p:0003 s:0068 e:000067 BLOCK  /srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/synchronization/mutex_ [FINISH]
c:0013 p:---- s:0065 e:000064 CFUNC  :synchronize
c:0012 p:0018 s:0061 e:000060 METHOD /srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/synchronization/mutex_
c:0011 p:0005 s:0057 e:000056 METHOD /srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/safe_task_exe
c:0010 p:0036 s:0052 e:000051 METHOD /srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/ivar.rb:169
c:0009 p:0010 s:0043 e:000042 METHOD /srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/scheduled_task.rb:285
c:0008 p:0006 s:0039 e:000038 BLOCK  /srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/timer_set.rb: [FINISH]
c:0007 p:0009 s:0036 e:000035 METHOD /srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_p
c:0006 p:0049 s:0028 e:000027 BLOCK  /srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_p [FINISH]
c:0005 p:---- s:0022 e:000021 CFUNC  :loop
c:0004 p:0006 s:0018 e:000017 BLOCK  /srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_p [FINISH]
c:0003 p:---- s:0015 e:000014 CFUNC  :catch
c:0002 p:0020 s:0010 e:000009 BLOCK  /srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_p [FINISH]
c:0001 p:---- s:0003 e:000002 (none) [FINISH]

-- Ruby level backtrace information ----------------------------------------
/srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:324:in `block in create_worker'
/srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:324:in `catch'
/srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:325:in `block (2 levels) in create_worker'
/srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:325:in `loop'
/srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:342:in `block (3 levels) in create_worker'
/srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:353:in `run_task'
/srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/timer_set.rb:98:in `block in ns_post_task'
/srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/scheduled_task.rb:285:in `process_task'
/srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/ivar.rb:169:in `safe_execute'
/srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:19:in `execute'
/srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:41:in `synchronize'
/srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:41:in `synchronize'
/srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:41:in `block in synchronize'
/srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:24:in `block in execute'
/srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/timer_task.rb:312:in `execute_task'
/srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:19:in `execute'
/srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:41:in `synchronize'
/srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:41:in `synchronize'
/srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:41:in `block in synchronize'
/srv/app/shared/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:24:in `block in execute'
/srv/app/shared/bundle/ruby/2.5.0/gems/elastic-apm-3.8.0/lib/elastic_apm/metrics.rb:70:in `block in start'
/srv/app/shared/bundle/ruby/2.5.0/gems/elastic-apm-3.8.0/lib/elastic_apm/metrics.rb:115:in `collect_and_send'
/srv/app/shared/bundle/ruby/2.5.0/gems/elastic-apm-3.8.0/lib/elastic_apm/metrics.rb:115:in `each'
/srv/app/shared/bundle/ruby/2.5.0/gems/elastic-apm-3.8.0/lib/elastic_apm/metrics.rb:116:in `block in collect_and_send'
/srv/app/shared/bundle/ruby/2.5.0/gems/elastic-apm-3.8.0/lib/elastic_apm/agent.rb:86:in `block in initialize'
/srv/app/shared/bundle/ruby/2.5.0/gems/elastic-apm-3.8.0/lib/elastic_apm/agent.rb:147:in `enqueue'
/srv/app/shared/bundle/ruby/2.5.0/gems/elastic-apm-3.8.0/lib/elastic_apm/transport/base.rb:83:in `submit'
/srv/app/shared/bundle/ruby/2.5.0/gems/elastic-apm-3.8.0/lib/elastic_apm/transport/base.rb:83:in `push'

-- Machine register context ------------------------------------------------
 RIP: 0x000055de875e19af RBP: 0x00007fb722b6af90 RSP: 0x00007fb7325c3e60
 RAX: 0x00007fb7325c91f8 RBX: 0x00007fb722b56f00 RCX: 0x00007fb722b56f00
 RDX: 0x00007fb73aa4d550 RDI: 0x0020000000000000 RSI: 0x00007fb72891ec00
  R8: 0x000055de875e1840  R9: 0x00007fb73aae6d90 R10: 0x0000000000000002
 R11: 0x00007fb71a9064e8 R12: 0x00007fb73aa4d548 R13: 0x000055de00000000
 R14: 0x00007fb71a906478 R15: 0x00007fb722b6af90 EFL: 0x0000000000010293

-- C level backtrace information -------------------------------------------
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de876c7d18) [0x55de876c7d18]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de876bc5f0) [0x55de876bc5f0]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de875a5f82) [0x55de875a5f82]
/lib64/libpthread.so.0(0x7fb73c33b5d0) [0x7fb73c33b5d0]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de875e19af) [0x55de875e19af]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8761a87c) [0x55de8761a87c]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8762bb43) [0x55de8762bb43]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8762358f) [0x55de8762358f]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de87628549) [0x55de87628549]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de87629200) [0x55de87629200]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de876294ad) [0x55de876294ad]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de87629597) [0x55de87629597]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8762b4cc) [0x55de8762b4cc]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8762bb43) [0x55de8762bb43]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8762358f) [0x55de8762358f]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de87628549) [0x55de87628549]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de87629200) [0x55de87629200]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(rb_yield+0xdc) [0x55de8762993c]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(rb_ary_each+0x3d) [0x55de8763f50d]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8761a87c) [0x55de8761a87c]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8762bb43) [0x55de8762bb43]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8762436b) [0x55de8762436b]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de87628549) [0x55de87628549]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de87629200) [0x55de87629200]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de876294ad) [0x55de876294ad]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de87629597) [0x55de87629597]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8762b4cc) [0x55de8762b4cc]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8762358f) [0x55de8762358f]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de87628549) [0x55de87628549]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de87629200) [0x55de87629200]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(rb_yield+0x259) [0x55de87629ab9]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(rb_ensure+0xca) [0x55de874ad64a]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8761a87c) [0x55de8761a87c]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8762436b) [0x55de8762436b]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de87628549) [0x55de87628549]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8762d0d4) [0x55de8762d0d4]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8762d570) [0x55de8762d570]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8762b3cb) [0x55de8762b3cb]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8762b4cc) [0x55de8762b4cc]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8762358f) [0x55de8762358f]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de87628549) [0x55de87628549]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de87629200) [0x55de87629200]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(rb_yield+0x259) [0x55de87629ab9]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(rb_ensure+0xca) [0x55de874ad64a]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8761a87c) [0x55de8761a87c]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8762436b) [0x55de8762436b]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de87628549) [0x55de87628549]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de87629200) [0x55de87629200]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de876294ad) [0x55de876294ad]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de87629597) [0x55de87629597]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8762b4cc) [0x55de8762b4cc]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8762358f) [0x55de8762358f]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de87628549) [0x55de87628549]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de87629200) [0x55de87629200]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8762a266) [0x55de8762a266]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(rb_rescue2+0xda) [0x55de874ad11a]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8761a87c) [0x55de8761a87c]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8762436b) [0x55de8762436b]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de87628549) [0x55de87628549]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de87629200) [0x55de87629200]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de87629fbb) [0x55de87629fbb]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8761d528) [0x55de8761d528]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8761d6dc) [0x55de8761d6dc]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8761a87c) [0x55de8761a87c]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de8762436b) [0x55de8762436b]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de87628549) [0x55de87628549]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de87629200) [0x55de87629200]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de876294ad) [0x55de876294ad]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de87629597) [0x55de87629597]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de875e3c26) [0x55de875e3c26]
unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080(0x55de875e4151) [0x55de875e4151]
/lib64/libpthread.so.0(0x7dd5) [0x7fb73c333dd5]
/lib64/libc.so.6(clone+0x6d) [0x7fb73b6ebead]

-- Other runtime information -----------------------------------------------

* Loaded script: unicorn worker[13] -c /srv/app/current/config/unicorn/production.rb -E production -D -l0.0.0.0:8080
@mikker
Copy link
Contributor

mikker commented Aug 18, 2020

Sounds like it's related to this #441. I see you're using Unicorn – could you provide your Unicorn config?

@mikker
Copy link
Contributor

mikker commented Aug 18, 2020

This issue is also related #504

@ota-akira
Copy link
Author

Thank you for the information that this is a problem with Ruby 2.5 and elastic-apm.
I also hope to get closer to solving the problem.

Below is my unicorn configuration.

  • production.rb
instance_eval File.read(File.join(__dir__, 'common.rb'))
_working_path = '/srv/app/current'

worker_processes 28
working_directory _working_path

before_exec do |server|
  ENV['BUNDLE_GEMFILE'] = File.join(_working_path, 'Gemfile')
end
  • common.rb
pid "tmp/pids/unicorn.pid"
stderr_path "log/unicorn.log"
stdout_path "log/unicorn.log"

timeout 60

# combine Ruby 2.0.0dev or REE with "preload_app true" for memory savings
# http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
  GC.copy_on_write_friendly = true

# Enable this flag to have unicorn test client connections by writing the
# beginning of the HTTP headers before calling the application.  This
# prevents calling the application for connections that have disconnected
# while queued.  This is only guaranteed to detect clients on the same
# host unicorn runs on, and unlikely to detect disconnects even on a
# fast LAN.
check_client_connection false

before_fork do |server, worker|
  # the following is highly recomended for Rails + "preload_app true"
  # as there's no need for the master process to hold a connection
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.connection.disconnect!
    ActiveRecord::Base.clear_all_replica_connections!
  end

  # The following is only recommended for memory/DB-constrained
  # installations.  It is not needed if your system can house
  # twice as many worker_processes as you have configured.
  #
  # This allows a new master process to incrementally
  # phase out the old master process with SIGTTOU to avoid a
  # thundering herd (especially in the "preload_app false" case)
  # when doing a transparent upgrade.  The last worker spawned
  # will then kill off the old master process with a SIGQUIT.
  old_pid = "#{server.config[:pid]}.oldbin"
  if old_pid != server.pid
    begin
      sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
      Process.kill(sig, File.read(old_pid).to_i)
    rescue Errno::ENOENT, Errno::ESRCH
    end
  end
  #
  # Throttle the master from forking too quickly by sleeping.  Due
  # to the implementation of standard Unix signal handlers, this
  # helps (but does not completely) prevent identical, repeated signals
  # from being lost when the receiving process is busy.
  sleep 1
end

after_fork do |server, worker|
  # per-process listener ports for debugging/admin/migrations
  # addr = "127.0.0.1:#{9293 + worker.nr}"
  # server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)

  # the following is *required* for Rails + "preload_app true",
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection and
    ActiveRecord::Base.establish_fresh_connection

  # if preload_app is true, then you may also want to check and
  # restart any other shared sockets/descriptors such as Memcached,
  # and Redis.  TokyoCabinet file handles are safe to reuse
  # between any number of forked children (assuming your kernel
  # correctly implements pread()/pwrite() system calls)
end

@mikker
Copy link
Contributor

mikker commented Aug 18, 2020

Try putting a ElasticAPM.restart inside your after_fork block (docs) and let me know if that makes a difference.

@ota-akira
Copy link
Author

Thanks mikker.

I'm trying it, and looks good working now 😃
(you seems like superman!)
I continue test on this configuration a while.

but I think, it is not cause of SEGV.
if you have more information to cause of SEGV, tell me more information.
regards!

@estolfo
Copy link
Contributor

estolfo commented Oct 6, 2020

@ota-akira Glad to hear it's working now!
Did you upgrade your ruby version as well?

@Matt-Yorkley
Copy link

Just a note for anyone else looking here: I have a similar forking Unicorn setup and adding ElasticAPM.restart in the after_fork block seems to mess up all the traces. It works fine without that change (using the latest version of the gem), possibly due to this: #763 👍

@ota-akira
Copy link
Author

thanks for all. (and sorry I'm late response.)

@estolfo
our team still using older version Ruby. (we trying to upgrade it.)

@Matt-Yorkley
thank you for great advice.
we applied latest version gem, but still seems to mess up all the traces.
we maked workaround is this:

  ElasticAPM.restart.tap do |agent|
    agent.instrumenter.subscriber = ElasticAPM::Subscriber.new(agent) if agent.present?
  end

usually attach to subscriber object at Rails start up.
but, ElasticAPM.restart not touch to subscriber object.

ElasticAPM.start(config).tap do |agent|
attach_subscriber(agent)
end

@estolfo
Copy link
Contributor

estolfo commented Feb 25, 2021

@Matt-Yorkley and @ota-akira As of version 3.7.0 of the agent, forking is detected automatically and the agent is restarted. So it shouldn't be necessary to restart the agent in an after_fork block. @Matt-Yorkley have you tried >= v3.7.0 of the agent and seen that it's not restarting the agent once forked? Here is the PR with the change.

@ota-akira If you've had to set the subscriber explicitly when it is restarted, that sounds like a bug that we should fix. When you say the traces are messed up, what do you mean?

@ota-akira
Copy link
Author

@estolfo
thank you for your comment.
we use version 3.8.0 agent, but still need restart on after_fork block. (and still occurred SEGV)

"Traces are messed up" means that transaction information cannot be logged.
(in Kibana visualization tools APM > Services > sevice_name > Transactions panel is blank 😢 )

we think this code replaces all tansaction.names with'Rack'.
it seems that the transaction cannot be logged on restart.

https://github.com/elastic/apm-agent-ruby/blob/master/lib/elastic_apm/normalizers/rails/action_controller.rb#L32

it sounds like bug, but we think "bottom cause is using Ruby 2.5".
if the problem not solved on after our Ruby version upgrade then we do additional investigation to find the cause.

thank you.

@estolfo
Copy link
Contributor

estolfo commented Oct 15, 2021

@ota-akira is this still an issue or can we close it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants