Project

General

Profile

Actions

Bug #13775

closed

Ruby hangs when calling scope and belongs_to many times (with mongomapper)

Added by mtsmfm (Fumiaki Matsushima) over 7 years ago. Updated over 7 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:82202]

Description

Following code will hang Ruby:

require 'bundler/setup'
require 'mongo_mapper'
MongoMapper.setup(
  {
    'development' => {
      'host' => 'mongo', 'port' => 27017, 'database' => 'db'
    }
  },
  'development'
)

class A
  include MongoMapper::Document

  10000.times do |i|
    scope :"scope_#{i}", order(:"order_#{i}")
    belongs_to :"col_#{i}"
  end
end

I confirmed that it will happen 2.4.1 and trunk (ruby 2.5.0dev (2017-07-18 trunk 59362) [x86_64-linux]).

Backtrace:

/vendor/bundle/gems/mongo_mapper-0.14.0/lib/mongo_mapper/plugins/associations/single_association.rb:8: [BUG] rb_gc_mark(): 0x0000000178d240 is T_NONE
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0015 p:---- s:0062 e:000061 CFUNC  :module_eval
c:0014 p:0125 s:0057 e:000056 METHOD /vendor/bundle/gems/mongo_mapper-0.14.0/lib/mongo_mapper/plugins/associations/single_association.rb:8
c:0013 p:0078 s:0052 e:000051 METHOD /vendor/bundle/gems/mongo_mapper-0.14.0/lib/mongo_mapper/plugins/associations/belongs_to_association.rb:21
c:0012 p:0033 s:0047 e:000046 METHOD /vendor/bundle/gems/mongo_mapper-0.14.0/lib/mongo_mapper/plugins/associations.rb:64
c:0011 p:0029 s:0042 e:000041 METHOD /vendor/bundle/gems/mongo_mapper-0.14.0/lib/mongo_mapper/plugins/associations.rb:14
c:0010 p:0013 s:0035 e:000034 BLOCK  main.rb:29 [FINISH]
c:0009 p:---- s:0031 e:000030 IFUNC
c:0008 p:---- s:0028 e:000027 CFUNC  :upto
c:0007 p:---- s:0025 e:000024 CFUNC  :each
c:0006 p:0018 s:0021 e:000020 METHOD /vendor/bundle/gems/activesupport-4.2.9/lib/active_support/core_ext/range/each.rb:7
c:0005 p:0037 s:0016 E:0007e0 CLASS  main.rb:28
c:0004 p:0011 s:0013 e:000012 BLOCK  main.rb:23 [FINISH]
c:0003 p:---- s:0010 e:000009 CFUNC  :times
c:0002 p:0068 s:0006 e:000005 EVAL   main.rb:22 [FINISH]
c:0001 p:0000 s:0003 E:001b80 (none) [FINISH]

Steps to reproduce:

git clone https://gist.github.com/dbbf1afabd372aa1269a954911292cfe.git
cd dbbf1afabd372aa1269a954911292cfe
docker-compose run ruby-2-4-1
docker-compose run ruby-trunk

Full backtrace in my gist.
https://gist.github.com/mtsmfm/dbbf1afabd372aa1269a954911292cfe


Related issues 2 (0 open2 closed)

Related to Ruby master - Feature #12628: change block/env structsClosedko1 (Koichi Sasada)Actions
Related to Ruby master - Bug #13772: Memory leak recycling stacks for threads in 2.4.1Closedko1 (Koichi Sasada)Actions

Updated by wanabe (_ wanabe) over 7 years ago

I couldn't reproduce because of lack of docker-compose.yml (and maybe Dockerfile).

$ docker-compose run ruby-2-4-1

ERROR: 
        Can't find a suitable configuration file in this directory or any
        parent. Are you in the right directory?

        Supported filenames: docker-compose.yml, docker-compose.yaml
        

Updated by mtsmfm (Fumiaki Matsushima) over 7 years ago

wanabe (_ wanabe) wrote:

I couldn't reproduce because of lack of docker-compose.yml (and maybe Dockerfile).

$ docker-compose run ruby-2-4-1

ERROR: 
        Can't find a suitable configuration file in this directory or any
        parent. Are you in the right directory?

        Supported filenames: docker-compose.yml, docker-compose.yaml
        

Oops!
Sorry, I committed and pushed!

Updated by wanabe (_ wanabe) over 7 years ago

mtsmfm (Fumiaki Matsushima) wrote:

Oops!
Sorry, I committed and pushed!

Thank you. reproduced.

I guess this is a GC issue.
Here is a reproducible code with cflags="-DRGENGC_CHECK_MODE=2" build.
this code works fine (= no [BUG]) without RGENGC_CHECK_MODE.

b = proc { }
10.times do |i|
  p i
  b.clone
  GC.start
end

I saw below output.

0
1
b.rb:5: [BUG] inconsistent old slot nubmer: expect 2916, but 2917.
ruby 2.5.0dev (2017-07-31 trunk 59454) [x86_64-linux]
(snip)

And git bisect shows that this is from r55766 [Feature #12628].

Actions #4

Updated by wanabe (_ wanabe) over 7 years ago

Actions #5

Updated by nobu (Nobuyoshi Nakada) over 7 years ago

  • Related to Bug #13772: Memory leak recycling stacks for threads in 2.4.1 added
Actions #6

Updated by ko1 (Koichi Sasada) over 7 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r59457.


should not copy promoted flags.

  • include/ruby/ruby.h (rb_clone_setup): should not copy some flags
    (FL_PROMOTED0|FL_PROMOTED1|FL_FINALIZE).
    [Bug #13775]

  • test/ruby/test_object.rb: add a test (note that this test will fail
    only when RGENGC_CHECK_MODE >= 2).

Actions #7

Updated by nagachika (Tomoyuki Chikanaga) over 7 years ago

  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: REQUIRED

Updated by nagachika (Tomoyuki Chikanaga) over 7 years ago

  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: REQUIRED to 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: DONE

ruby_2_4 r59520 merged revision(s) 59457.

Actions #9

Updated by usa (Usaku NAKAMURA) over 7 years ago

  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: DONE to 2.2: DONTNEED, 2.3: DONTNEED, 2.4: DONE
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0