#309 open
Aslak Hellesøy

Fix for RCov Segfault

Reported by Aslak Hellesøy | February 26th, 2008 @ 09:34 AM | in 1.1.5

I have experienced intermittant segfaults with rcov. It seems to be related to how RSpec exits. It currently calls exit(true) or exit(false), which is nuts. exit needs an int. When I change the spec script to this, rcov never seems to segfault.

#!/usr/bin/env ruby
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
require 'spec'
success = ::Spec::Runner::CommandLine.run(rspec_options)
exit 1 unless success

Comments and changes to this ticket

  • Aslak Hellesøy

    Aslak Hellesøy February 26th, 2008 @ 12:22 PM

      • → State changed from “new” to “open”

    Same goes for Story::Runner:

    def register_exit_hook # :nodoc:
      at_exit do
        success = Runner.story_runner.run_stories
        exit 1 unless success
      end
    end
    
  • Ian White

    Ian White May 1st, 2008 @ 07:59 PM

    I'm getting intermittent rcov segfaults as well.

    However, I've applied your changes and I'm still getting them. (That's obviously not to say that your fixes don't fix some problems)

  • Ian White

    Ian White May 1st, 2008 @ 08:03 PM

    I tried applying it to the scripts in rspec-rails.

    Also, script/generate rspec to update the runner scripts (if your in a rails proj)

    Still getting the failures

  • Geoff Garside

    Geoff Garside May 7th, 2008 @ 01:27 PM

    I've tried these as well and still got segfaults. Though I shortened the patch to

    exit 1 unless ::Spec::Runner::CommandLine.run(rspec_options)
    

    I think I'll be building a debug version of Ruby and doing some digging through core files.

    Out of interest where are you seeing your segfaults strike? I'm getting them on introspection.rb, symbol.rb in ActiveSupport with "rb_gc_mark() called for broken object".

  • David Chelimsky

    David Chelimsky May 27th, 2008 @ 07:45 AM

      • → Milestone changed from “1.1.4” to “1.1.5”
  • Emmanuel Oga

    Emmanuel Oga June 9th, 2008 @ 06:39 PM

    I'm getting the same problem.

    NOTE: This happens truly __randomly__, I ran rake spec:rcov a lot of times (like, say, ten times), the eleventh time it could generate the coverage report without problems.

    NOTE2: This happens with all versions of rcov, I tried from 0.5.0.1 up to the last, 0.8.1.2

    NOTE3: Sorry, the fix described in the ticket don't takes the problem away.

    This is my trace when I get the problem:

    $ ruby --version

    ruby 1.8.6 (2008-03-03 patchlevel 114) [i686-linux]

    $ rcov --version

    rcov 0.8.1.2 2007-11-22

    $ rake spec:rcov --trace

    (in /home/emmanuel/work/sailboat)

    ** Invoke spec:rcov (first_time)

    ** Invoke spec:clobber_rcov (first_time)

    ** Execute spec:clobber_rcov

    ** Execute spec:rcov

    DEPRECATION WARNING: config.action_view.cache_template_extensions option has been deprecated and has no affect. Please remove it from your config files. See http://www.rubyonrails.org/depre... for details. (called from /home/emmanuel/work/sailboat/vendor/plugins/rspec-rails/lib/spec/rails/example/rails_example_group.rb:3)

    ................P..................................................................................../home/emmanuel/work/sailboat/lib/authenticated_system.rb:17: warning: Object#id will be deprecated; use Object#object_id

    ./home/emmanuel/work/sailboat/lib/authenticated_system.rb:17: warning: Object#id will be deprecated; use Object#object_id

    ....................../usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/routing/route.rb:94: [BUG] rb_gc_mark(): unknown data type 0x20(0x8e652a8) non object

    ruby 1.8.6 (2008-03-03) [i686-linux]

    Aborted

    rake aborted!

    Command /usr/bin/ruby -I"/home/emmanuel/work/sailboat/vendor/plugins/rspec/lib" -S rcov --exclude "spec/*,gems/*" --rails -o "coverage" "/home/emmanuel/work/sailboat/vendor/plugins/rspec/bin/spec" -- ...LOTS OF FILES :-)... failed

    /home/emmanuel/work/sailboat/vendor/plugins/rspec/lib/spec/rake/spectask.rb:184:in `define'

    /usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1003:in `verbose'

    /home/emmanuel/work/sailboat/vendor/plugins/rspec/lib/spec/rake/spectask.rb:153:in `define'

    /usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `call'

    /usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `execute'

    /usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `each'

    /usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `execute'

    /usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:508:in `invoke_with_call_chain'

    /usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `synchronize'

    /usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `invoke_with_call_chain'

    /usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:494:in `invoke'

    /usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1931:in `invoke_task'

    /usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'

    /usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `each'

    /usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'

    /usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'

    /usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1903:in `top_level'

    /usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1881:in `run'

    /usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'

    /usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1878:in `run'

    /usr/lib/ruby/gems/1.8/gems/rake-0.8.1/bin/rake:31

    /usr/bin/rake:19:in `load'

    /usr/bin/rake:19

  • Dave Nawara

    Dave Nawara June 14th, 2008 @ 09:48 PM

    The fixes don't seem to work for me. I'm using mysql for my db. OS 10.5.3 on an early intel MBP (core duo).

    $ ruby --version

    ruby 1.8.6 (2007-09-24 patchlevel 111) [universal-darwin9.0]

    $ rcov --version

    rcov 0.8.1.2 2007-11-22

    The segfault first occurred after I added a new controller spec. Sometimes I get a segfault, sometimes I get "rb_gc_mark() called for broken object." It all seems to depend on the structure of my spec file. I can change the error by moving things around in my spec file. Sometimes things run/don't run depending on whitespace. Removing one spec currently makes everything pass for me. I can also make everything pass by moving a spec file out if my specs dir (same concept as removing a spec, I suppose). I seem to be at some sort of threshold for file size.

    Depending on text content of my spec file, I've hit:

    /Library/Ruby/Gems/1.8/gems/colored-1.1/lib/colored.rb:87: [BUG] rb_gc_mark() called for broken object

    spec/controllers/roles_routing_spec.rb:27: [BUG] rb_gc_mark() called for broken object

    rspec-rails/lib/spec/rails/example/controller_example_group.rb:156: [BUG] Segmentation fault

    My full trace is very similar to the post above:

    $ rake spec:rcov --trace

    (in /Users/dave/dev/workspace/djn2ms)

    ** Invoke spec:rcov (first_time)

    ** Invoke spec:clobber_rcov (first_time)

    ** Execute spec:clobber_rcov

    ** Execute spec:rcov

    ....../Users/dave/dev/workspace/djn2ms/vendor/plugins/rspec-rails/lib/spec/rails/example/controller_example_group.rb:156: [BUG] Segmentation fault

    ruby 1.8.6 (2007-09-24) [universal-darwin9.0]

    rake aborted!

    Command /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I"/Users/dave/dev/workspace/djn2ms/vendor/plugins/rspec/lib" -S rcov --exclude "spec/*,gems/*" --rails -o "coverage" "/Users/dave/dev/workspace/djn2ms/vendor/plugins/rspec/bin/spec" -- LOTS OF FILES TOO :¬) --options "/Users/dave/dev/workspace/djn2ms/spec/spec.opts" failed

    /Users/dave/dev/workspace/djn2ms/vendor/plugins/rspec/lib/spec/rake/spectask.rb:177:in `define'

    /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1003:in `verbose'

    /Users/dave/dev/workspace/djn2ms/vendor/plugins/rspec/lib/spec/rake/spectask.rb:153:in `define'

    /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `call'

    /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `execute'

    /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `each'

    /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `execute'

    /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:508:in `invoke_with_call_chain'

    /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `synchronize'

    /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `invoke_with_call_chain'

    /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:494:in `invoke'

    /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1931:in `invoke_task'

    /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'

    /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `each'

    /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'

    /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'

    /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1903:in `top_level'

    /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1881:in `run'

    /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'

    /Library/Ruby/Gems/1.8/gems/rake-0.8.1/lib/rake.rb:1878:in `run'

    /Library/Ruby/Gems/1.8/gems/rake-0.8.1/bin/rake:31

    /usr/bin/rake:19:in `load'

    /usr/bin/rake:19

    If I wasn't such a ruby nuby, i'd track this down myself.

  • Michael Moen

    Michael Moen July 19th, 2008 @ 12:49 AM

      • → Tag changed from “” to “rcov”

    I ran into this problem today and figured I would see if I could find anything causing the issue. It started with the following segfault.

    plugins/rspec/lib/spec/example/example_group_methods.rb:417: [BUG] rb_gc_mark(): unknown data type 0x0(0x1c80834) non object

    So I figured I would print out the values as they went by to see when it blew up. Then I got the following.

    plugins/rspec/lib/spec/example/example_group_methods.rb:421: [BUG] rb_gc_mark(): unknown data type 0x0(0x1c80834) non object

    So I put a print in there as well. And after doing noting but putting in a couple print statements it was happy. yeah, it makes no sense to me either.

    Of course that was way too much output so I just commented them out figuring I would come back to it later. Even with the prints commented out it works. Now if I remove any of them it immediately breaks.

    I'm sure this is not much use, but I figured I'd share.

    Here's the diff as it is now.

    Index: lib/spec/example/example_group_methods.rb

    ===================================================================

    --- lib/spec/example/example_group_methods.rb (revision 26)

    +++ lib/spec/example/example_group_methods.rb (working copy)

    @@ -414,8 +414,12 @@

    end

    def add_method_examples(examples)

    • # print instance_methods.inspect

    instance_methods.sort.each do |method_name|

    • # print ''
    • # print method_name.inspect

    if example_method?(method_name)

    • # print ''

    examples << new(method_name) do

    __send__(method_name)

    end

  • Michael Moen

    Michael Moen July 19th, 2008 @ 12:50 AM

    Ok, that diff doesn't look very friendly in there, attaching a file.

  • Michael Moen
  • Christian Buggle

    Christian Buggle August 5th, 2008 @ 10:57 AM

    ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]

    rcov 0.8.1.2 2007-11-22

    I am experiencing the same problem with virtually identical error messages (SegFault, Bus Error, rb_gc_mark(): unknown data type 0x20(0x28f547c) non object), and slightly altering spec files changes the error. The described Patch didn't change anything.

    Today i managed to get one (1) successful run (after dozens of failures) by restarting all terminal windows. After the successfull run i started autotest in a second terminal, which again led to the rcov crash.

  • schorsch

    schorsch August 13th, 2008 @ 09:45 PM

      • → Assigned user cleared.

    same problems as all above. using rails with normal unit tests and rspec.

    random errors

    ruby 1.8.6 (2007-09-24 patchlevel 111) [i486-linux]

    rcov (0.8.1.2.0)

  • Georg Ledermann

    Georg Ledermann August 13th, 2008 @ 11:22 PM

      • → Assigned user changed from “” to “David Chelimsky”

    Same here: Starting "rake spec:rcov" on a bigger project runs the suite, but in the middle it breaks with this messsage:

    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/routing/routing_ext.rb:28: [BUG] Bus Error ruby 1.8.6 (2007-09-24) [i686-darwin9.1.0]

    My environment: - OSX 10.5.4 - Ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-darwin9.1.0] - Rails 2.1 - RSpec 1.1.4 - rcov 0.8.1.2.0

    For testing purpose I created a new dummy rails project with a few specs - and this project runs fine with rcov... Strange.

  • Steven Holloway

    Steven Holloway August 19th, 2008 @ 02:41 AM

    I get such error (seg fault and bus error) randomly in different parts of the test suite. the only theme i have found is they seem to occur near "response.should redirect_to" but not always. this project is in the final stages of a rails 2.1 upgrade. Somtimes run all the way through. rspec 1.1.4 rcov 0.8.1.2 ruby 1.8.6 p111 OS X 10.5.4

  • Marcos Tapajós

    Marcos Tapajós August 25th, 2008 @ 01:41 AM

    I get such error (seg fault and bus error) randomly in different parts of the test suite.

    
    (tapajos@tapanote:~)$ ruby --version
    ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]
    (tapajos@tapanote:~)$
    
    (tapajos@tapanote:~)$ rcov --version
    rcov 0.8.1.2 2007-11-22
    (tapajos@tapanote:~)$
    
    (tapajos@tapanote:beonthenet(master))$ rake spec:rcov
    (in /Users/tapajos/workspace/beonthenet)
    .........................................................................
    .........................................................................
    .........................................................................
    .........................................................................
    .........................................................................
    .........................................................................
    .........................................................................
    ............................................................
    /Users/tapajos/workspace/beonthenet/vendor/plugins/rspec/lib/spec/example/example_group_methods.rb:368: [BUG] Bus Error
    ruby 1.8.6 (2008-03-03) [universal-darwin9.0]
    
    rake aborted!
    Command /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I"/Users/tapajos/workspace/beonthenet/vendor/plugins/rspec/lib" -S rcov --exclude "spec/*,gems/*" --rails -o "coverage" "/Users/tapajos/workspace/beonthenet/vendor/plugins/rspec/bin/spec" --
    
  • Robby Russell

    Robby Russell August 25th, 2008 @ 01:40 AM

    Am having similar problem when I try to run specs.

    
    --options "/Users/robbyrussell/Projects/development/clients/alphaclone/alphaclone/spec/spec.opts" failed
    /Users/robbyrussell/Projects/development/clients/alphaclone/alphaclone/vendor/plugins/rspec/lib/spec/rake/spectask.rb:177:in `define'
    /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1003:in `verbose'
    /Users/robbyrussell/Projects/development/clients/alphaclone/alphaclone/vendor/plugins/rspec/lib/spec/rake/spectask.rb:153:in `define'
    /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `call'
    /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `execute'
    /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `each'
    /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `execute'
    /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:508:in `invoke_with_call_chain'
    /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `synchronize'
    /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `invoke_with_call_chain'
    /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:494:in `invoke'
    /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1931:in `invoke_task'
    /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'
    /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `each'
    /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'
    /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'
    /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1903:in `top_level'
    /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1881:in `run'
    /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'
    /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1878:in `run'
    /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/bin/rake:31
    /opt/local/bin/rake:19:in `load'
    /opt/local/bin/rake:19
    
  • Daniel Berger

    Daniel Berger August 27th, 2008 @ 12:21 AM

    Users may be interested in this post from Tom Copeland:

    http://tomcopeland.blogs.com/jun...

  • Tom Copeland

    Tom Copeland August 29th, 2008 @ 04:53 AM

    There's a slightly better patch there now:

    http://tomcopeland.blogs.com/jun...

    Rather than just commenting things out I added some bounds checks around accesses to the ptr member of that cov_array struct. Would be interesting to figure out how it's going wrong in the first place though...

  • Sylvestre Mergulhão

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)