Project

General

Profile

Actions

Bug #17529

open

Ractor Segfaults with GC enabled

Added by prajjwal (Prajjwal Singh) 4 months ago. Updated 3 months ago.

Status:
Assigned
Priority:
Normal
Target version:
-
ruby -v:
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
[ruby-core:102008]

Description

I've been benchmarking Ractor on my machine with the following naive prime number generator:

# frozen_string_literal: true

def prime?(n)
  2.upto(n - 1).none? { |i| n % i == 0 }
end

NUM_WORKERS = ARGV[0].to_i

producer = Ractor.new do
  i = 1000000

  loop { Ractor.yield i; i += 1 }
end

workers = (1..NUM_WORKERS).map do
  Ractor.new producer do |producer|
    while n = producer.take
      Ractor.yield [n, prime?(n)]
    end
  end
end

loop do
  _r, ( number, prime ) = Ractor.select(*workers)

  p number if prime
end

The code inevitably segfaults, and it appears to be the garbage collector.

If I stick GC.disable in there, the code happily chugs along for several minutes on end without a problem.


Files

ractor.crash (22.5 KB) ractor.crash prajjwal (Prajjwal Singh), 01/12/2021 01:12 AM

Related issues

Related to Ruby master - Bug #17489: Ractor segfaultsAssignedko1 (Koichi Sasada)Actions
Actions #2

Updated by marcandre (Marc-Andre Lafortune) 4 months ago

Updated by marcandre (Marc-Andre Lafortune) 4 months ago

Thanks for the report.

Probably the same bug as #17489

Updated by ko1 (Koichi Sasada) 4 months ago

I couldn't reproduce it. Could you tell me ARGV[0]?

BTW please fill "ruby -v:" filed with your environment (even if it is in crash log)

ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]

Updated by prajjwal (Prajjwal Singh) 4 months ago

ko1 (Koichi Sasada)

It crashes for any value of ARGV[0] between 1 and 25 (that I tested).

The fact that its happening so consistently for me and not for you makes me wonder if the problem stems from my version of Linux or GCC? Some other compile time option perhaps?

Here's my GCC version:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --with-isl --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-install-libiberty --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-libunwind-exceptions --disable-werror gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.0 (GCC) 

And Linux:

Linux Wraith 5.9.14-arch1-1 #1 SMP PREEMPT Sat, 12 Dec 2020 14:37:12 +0000 x86_64 GNU/Linux

Ruby Configure Args

'--prefix=/home/prajjwal/.rbenv/versions/3.0.0' '--enable-shared' 'LDFLAGS=-L/home/prajjwal/.rbenv/versions/3.0.0/lib ' 'CPPFLAGS=-I/home/prajjwal/.rbenv/versions/3.0.0/include '
Actions #6

Updated by prajjwal (Prajjwal Singh) 4 months ago

  • ruby -v changed from 3.0.0 to ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]

Updated by prajjwal (Prajjwal Singh) 4 months ago

Just confirmed that it only segfaults when ruby is configured with the --enable-shared option (which rbenv does by default).

Even more info:

glibc 2.32-5

Updated by ko1 (Koichi Sasada) 3 months ago

  • Assignee set to ko1 (Koichi Sasada)
  • Status changed from Open to Assigned
Actions #9

Updated by ko1 (Koichi Sasada) 3 months ago

hmm I can't reproduce it yet. Can someone try it and get more information about it?

Actions

Also available in: Atom PDF