Project

General

Profile

Actions

Bug #19922

closed

ObjectSpace.dump_all in multiple threads in parallel causes SEGV

Bug #19922: ObjectSpace.dump_all in multiple threads in parallel causes SEGV

Added by wanabe (_ wanabe) almost 3 years ago. Updated 5 days ago.

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

Description

ObjectSpace.dump_all in multiple threads in parallel causes SEGV.
The reproduce code is here:

$ ruby -robjspace -e 'def dump; 10.times { ObjectSpace.dump_all } end; Thread.new { dump }; dump'
/home/wanabe/.rbenv/versions/master/lib/ruby/3.3.0+0/objspace.rb:100: [BUG] Segmentation fault at 0x0000000000000000
(snip)

I attached the full log.

I assumed that:

  • Thread1
    • calls rb_objspace_reachable_objects_from_root()
    • changes GET_RACTOR()->mfd: mfd1
    • calls dump_flush()
      • changes current thread due to IO
  • Thread2
    • calls rb_objspace_reachable_objects_from_root()
    • changes GET_RACTOR()->mfd: mfd2
    • calls dump_flush()
      • changes current thread due to IO
  • Thread1
    • gets unexpected GET_RACTOR()->mfd: mfd2

Files

bug.log (23.1 KB) bug.log wanabe (_ wanabe), 10/12/2023 12:44 PM

Updated by kjtsanaktsidis (KJ Tsanaktsidis) over 2 years ago Actions #1 [ruby-core:115289]

I think your diagnosis is correct, and that https://github.com/ruby/ruby/pull/8858 should fix this - does it look reasonable to you?

Updated by byroot (Jean Boussier) over 2 years ago Actions #3 [ruby-core:115354]

  • Status changed from Open to Closed

Fixed in 76dc327eeffefe02577999fe5f8215f762a581b6 and 9a62fd3cbae2ebb60e2f9cad782af1ad18db4319

Updated by byroot (Jean Boussier) over 2 years ago Actions #4 [ruby-core:115360]

  • Status changed from Closed to Open

Reopening because the fix caused a failure on ruby-ci, so we'll revert for now.

Updated by wanabe (_ wanabe) 5 days ago Actions #5 [ruby-core:126124]

  • Status changed from Open to Closed

This issue was fixed in commit 3c63a01295b4219743b3d3e883fd4a4a616960a and has not recurred since then.
Thank you.

$ git checkout 3c63a01295b4219743b3d3e883fd4a4a616960a6; make -j8 exts >/dev/null 2>&1 && ./ruby -v -I .ext/x86_64-linux/ -I .ext/common/ -I ../../lib -I. -robjspace -e 'def dump; 100.times { ObjectSpace.dump_all } end; Thread.new { dump }; dump; p :ok' 2>&1|head -n2
HEAD is now at 3c63a01295 Move responsibility of heap walking into Ruby
ruby 3.4.0dev (2024-09-03T14:05:38Z v3_4_0_preview2~649 3c63a01295) [x86_64-linux]
:ok

$ git checkout 3c63a01295b4219743b3d3e883fd4a4a616960a6~; make -j8 exts >/dev/null 2>&1 && ./ruby -v -I .ext/x86_64-linux/ -I .ext/common/ -I ../../lib -I. -robjspace -e 'def dump; 100.times { ObjectSpace.dump_all } end; Thread.new { dump }; dump; p :ok' 2>&1|head -n2
Previous HEAD position was 3c63a01295 Move responsibility of heap walking into Ruby
HEAD is now at a2243ee48b Implement ALIAS NODE keyword locations
ruby 3.4.0dev (2024-09-03T13:09:08Z v3_4_0_preview2~650 a2243ee48b) [x86_64-linux]
/home/wanabe/work/prog/ruby/ruby/tmp/master/.ext/common/objspace.rb:100: [BUG] Segmentation fault at 0x0000000000000000
Actions

Also available in: PDF Atom