Project

General

Profile

Actions

Bug #11799

closed

Object allocation during garbage collection phase terminates the Ruby process

Added by charlez (Charles Leu) almost 9 years ago. Updated almost 9 years ago.

Status:
Third Party's Issue
Assignee:
-
Target version:
-
ruby -v:
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
[ruby-core:72009]

Description

Resurrection of Bug #11549 that was apparently inadvertently deleted.
Also note the similarity to Bug #10868.

Summary: Multi-Threaded Ruby apps are often problematic; especially so when utilizing thread pools, and scheduling work to worker threads.

  • While the problem isn't easily recreated, it can be reliably recreated given sufficient time and conditions (for garbage collection in conjunction with sibling thread behavior).
  • Initially, three trace files have been attached. Each shows the problem in different conditions, and using different client infrastructure.
  • If this is a problem due to usage of certain gems that aren't 'well-behaved', it would be good to know which ones to avoid.

RE: attached file ruby_2.2.3_obj_alloc_gc_bug.txt

Following is the section of sap_consumer_control.rb that is presented by the Ruby interpreter as being the current execution context when the problem occurs.

408: loop do
409: @worker_threads.schedule(@work_queue.pop, &@consumer)
410: @sap_packets_consumed += 1
411: end

Notes:

  • @work_queue is a Ruby Queue (allocated within the main thread) into which a producer thread places work requests.
  • @worker_threads is a thread pool (allocated within the main thread).
  • @worker_threads schedule method simply puts a work request into the thread pool's internal work queue. One of the worker threads within the thread pool will consume/effect the work request, by executing the specified consumer Proc.
  • The main program thread simply loops forever scheduling work to thread pool threads.
  • It appears that an object is being allocated by virtue of the @work_queue.pop

RE: attached file ruby_bug_redis_client.txt

  • The observed behavior also occurs readily when employing the Redis client gem.
  • This is the use case in which the bug is most easily reproduced.

RE: attached file ruby_bug-gdb.txt

  • The observed behavior has also been observed when using stretcher, faraday, net-http-persistent gems.
  • Connections via stretcher to net-http-persistent are on a per thread basis (maintained within thread local storage).
  • In this particular case, the Ruby process was run under gdb, and back traces for each of the process threads are provided.

Files

ruby_bug_redis_client.txt (53.3 KB) ruby_bug_redis_client.txt charlez (Charles Leu), 12/09/2015 09:37 PM
ruby_2.2.3_obj_alloc_gc_bug.txt (49.1 KB) ruby_2.2.3_obj_alloc_gc_bug.txt charlez (Charles Leu), 12/09/2015 09:43 PM
ruby_bug-gdb.txt (151 KB) ruby_bug-gdb.txt charlez (Charles Leu), 12/09/2015 10:13 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0