Project

General

Profile

Actions

Bug #14578

closed

Forking a child process inside of a mutex crashes the ruby interpreter

Added by bengovero (Ben Govero) over 6 years ago. Updated over 6 years ago.

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

Description

OS: Mac OS X 10.13.3 (High Sierra)
Affects ruby versions 2.5.0 and 2.6.0preview1

Issue not present in 2.4.1

Consider the following script. I contrived it as an experiment for a more complicated project. We have a resource that we want to synchronize access to, but we want to fork the process when actually using the resource. This script works in 2.4.1, but not in 2.5.0 or beyond.

class Synchronizer

  def initialize
    @mutex = Mutex.new
  end

  def use(&block)
    @mutex.synchronize do
      Process.fork do
        block.call
      end

      Process.wait
    end
  end

end

@s = Synchronizer.new

5.times do |i|
  Thread.new do
    @s.use do
      puts "block #{i}"
    end
  end
end

sleep 10

The error I get when the interpreter crashes is: [BUG] unexpected THREAD_KILLED

Is this a crazy implementation? Or a real bug?


Files

ruby_2018-03-05-133827-1_bens-mac.crash (36.3 KB) ruby_2018-03-05-133827-1_bens-mac.crash bengovero (Ben Govero), 03/05/2018 07:43 PM
ruby_2018-03-05-133827_bens-mac.crash (36.3 KB) ruby_2018-03-05-133827_bens-mac.crash bengovero (Ben Govero), 03/05/2018 07:43 PM
ruby_2018-03-05-133827-2_bens-mac.crash (36.3 KB) ruby_2018-03-05-133827-2_bens-mac.crash bengovero (Ben Govero), 03/05/2018 07:43 PM

Updated by normalperson (Eric Wong) over 6 years ago

wrote:

https://bugs.ruby-lang.org/issues/14578

My fault. r58604 ("reduce rb_mutex_t size from 160 to 80 bytes on 64-bit")
Hope I can fix it soon before I'm offline.

Actions #2

Updated by normalperson (Eric Wong) over 6 years ago

  • Backport changed from 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN to 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: REQUIRED
Actions #3

Updated by Anonymous over 6 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r62668.


thread.c: reset waitq of keeping mutexes in child

We must not maintain references to threads in the parent process
in any mutexes held by the child process.

  • thread_sync.c (rb_mutex_cleanup_keeping_mutexes): new function
  • thread.c (rb_thread_atfork): cleanup keeping mutexes
    [ruby-core:85940] [Bug #14578]

Fixes: r58604 (commit 3586c9e0876e784767a1c1adba9ebc2499fa0ec2)
("reduce rb_mutex_t size from 160 to 80 bytes on 64-bit")

Updated by normalperson (Eric Wong) over 6 years ago

Eric Wong wrote:

wrote:

https://bugs.ruby-lang.org/issues/14578

My fault. r58604 ("reduce rb_mutex_t size from 160 to 80 bytes on 64-bit")
Hope I can fix it soon before I'm offline.

r62668 works for me; care to give it a shot?

Updated by naruse (Yui NARUSE) over 6 years ago

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

ruby_2_5 r62852 merged revision(s) 62668.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0