Project

General

Profile

Bug #13305

Occasional segfaults after defining methods while running coverage

Added by decuplet (Nikita Shilnikov) about 2 years ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16], ruby 2.5.0dev (2017-03-13 trunk 57944) [x86_64-darwin16]
[ruby-core:80079]

Description

The problem occurs on MRI 2.4.0 and the latest trunk only (2017-03-13 trunk 57944). After running Coverage.start code defines the same method few times but every time the size of the method increases. Occasionally MRI can fail on attempt to get the coverage result. The bug can be reproduced quite easily with the following two files

a.rb

require 'coverage'
Coverage.start

require_relative './b'

add_method(Class.new)

Coverage.result

b.rb

REPEATS = 400

def add_method(target)
  REPEATS.times do
    target.class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
      def foo
        #{"\n" * rand(REPEATS)}
      end
      1
    RUBY
  end
end

Run ruby a.rb to reproduce the bug. Several runs may be required before MRI fails, but for me it fails on almost every run.

Note that passing filename and line number to class_eval is important, so as adding 1 after the method definition.

The crash report attached to the issue.


Files


Related issues

Related to Ruby trunk - Bug #13594: Segfault in gc_sweep_step 2.4.1OpenActions

Associated revisions

Revision 3c96f9c7
Added by mame (Yusuke Endoh) about 2 years ago

Fix a consistency bug of ISEQ_COVERAGE [Bug #13305]

There is an invariant that ISEQ_COVERAGE(iseq) must be Qnil if and only
if option->coverage_enabled is false. This invariant was broken by
NODE_PRELUDE which updates option->coverage_enabled but not
ISEQ_COVERAGE(iseq).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57971 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 57971
Added by mame (Yusuke Endoh) about 2 years ago

Fix a consistency bug of ISEQ_COVERAGE [Bug #13305]

There is an invariant that ISEQ_COVERAGE(iseq) must be Qnil if and only
if option->coverage_enabled is false. This invariant was broken by
NODE_PRELUDE which updates option->coverage_enabled but not
ISEQ_COVERAGE(iseq).

Revision 57971
Added by mame (Yusuke Endoh) about 2 years ago

Fix a consistency bug of ISEQ_COVERAGE [Bug #13305]

There is an invariant that ISEQ_COVERAGE(iseq) must be Qnil if and only
if option->coverage_enabled is false. This invariant was broken by
NODE_PRELUDE which updates option->coverage_enabled but not
ISEQ_COVERAGE(iseq).

Revision 57971
Added by mame (Yusuke Endoh) about 2 years ago

Fix a consistency bug of ISEQ_COVERAGE [Bug #13305]

There is an invariant that ISEQ_COVERAGE(iseq) must be Qnil if and only
if option->coverage_enabled is false. This invariant was broken by
NODE_PRELUDE which updates option->coverage_enabled but not
ISEQ_COVERAGE(iseq).

Revision 6f1dc851
Added by nagachika (Tomoyuki Chikanaga) over 1 year ago

merge revision(s) 57971: [Backport #13305]

Fix a consistency bug of ISEQ_COVERAGE [Bug #13305]

There is an invariant that ISEQ_COVERAGE(iseq) must be Qnil if and only
if option->coverage_enabled is false.  This invariant was broken by
NODE_PRELUDE which updates option->coverage_enabled but not
ISEQ_COVERAGE(iseq).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@61414 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 61414
Added by nagachika (Tomoyuki Chikanaga) over 1 year ago

merge revision(s) 57971: [Backport #13305]

Fix a consistency bug of ISEQ_COVERAGE [Bug #13305]

There is an invariant that ISEQ_COVERAGE(iseq) must be Qnil if and only
if option->coverage_enabled is false.  This invariant was broken by
NODE_PRELUDE which updates option->coverage_enabled but not
ISEQ_COVERAGE(iseq).

History

Updated by decuplet (Nikita Shilnikov) about 2 years ago

  • Description updated (diff)

Updated by shyouhei (Shyouhei Urabe) about 2 years ago

  • Assignee set to mame (Yusuke Endoh)
  • Status changed from Open to Assigned

Updated by mame (Yusuke Endoh) about 2 years ago

Thank you for the report. I could reproduce the issue. I'll take a look later.

#4

Updated by mame (Yusuke Endoh) about 2 years ago

  • Status changed from Assigned to Closed

Applied in changeset r57971.


Fix a consistency bug of ISEQ_COVERAGE [Bug #13305]

There is an invariant that ISEQ_COVERAGE(iseq) must be Qnil if and only
if option->coverage_enabled is false. This invariant was broken by
NODE_PRELUDE which updates option->coverage_enabled but not
ISEQ_COVERAGE(iseq).

Updated by mame (Yusuke Endoh) about 2 years ago

I think I could fix the issue. Nikita, thank you for the very useful report!

Updated by decuplet (Nikita Shilnikov) about 2 years ago

mame (Yusuke Endoh) wrote:

I think I could fix the issue. Nikita, thank you for the very useful report!

Awesome! Thank you, can confirm, I tested the latest trunk in the environment where I had found the issue and the build passed https://travis-ci.org/rom-rb/rom-sql/builds/211705504 It fails on MRI 2.4.0-p0, but that's OK.

#7

Updated by wanabe (_ wanabe) almost 2 years ago

  • Related to Bug #13594: Segfault in gc_sweep_step 2.4.1 added

Updated by nelhage (Nelson Elhage) over 1 year ago

Can this fix be backported to the Ruby 2.4 release series? 2.4.3 is still affected by this crash.

#9

Updated by hsbt (Hiroshi SHIBATA) over 1 year 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 1 year 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 r61414 merged revision(s) 57971.

#11

Updated by usa (Usaku NAKAMURA) about 1 year ago

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

Also available in: Atom PDF