forkbreak / fork_break

Fork with breakpoints, for testing multiprocess behaviour.
MIT License
61 stars 6 forks source link

no _dump_data is defined for class Binding (TypeError) #16

Closed vemv closed 4 years ago

vemv commented 8 years ago

given the following super-simple class:

class Foo < ActiveRecord::Base

  include ForkBreak::Breakpoints

  def repro
    breakpoints << :transaction
  end

  def self.demo
    process1 = ForkBreak::Process.new {
      Foo.new.repro
    }
    process1.run_until(:transaction).wait
  end

end

running rails runner Foo.demo will throw the following:

/Users/vemv/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/fork-1.0.1/lib/fork.rb:91:in `dump': no _dump_data is defined for class Binding (TypeError)
    from /Users/vemv/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/fork-1.0.1/lib/fork.rb:91:in `write_marshalled'
    from /Users/vemv/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/fork-1.0.1/lib/fork.rb:631:in `rescue in rescue in child_process'
    from /Users/vemv/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/fork-1.0.1/lib/fork.rb:622:in `rescue in child_process'
    from /Users/vemv/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/fork-1.0.1/lib/fork.rb:640:in `child_process'
    from /Users/vemv/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/fork-1.0.1/lib/fork.rb:244:in `block in execute'
    from /Users/vemv/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/fork-1.0.1/lib/fork.rb:237:in `fork'
    from /Users/vemv/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/fork-1.0.1/lib/fork.rb:237:in `execute'
    from /Users/vemv/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/fork_break-d940d29d4e64/lib/fork_break/process.rb:24:in `run_until'
    from /Users/vemv/fork_break_repro/app/models/foo.rb:13:in `demo'

Same if I try to execute Foo.demo from a rails c session. With the only difference that I have to press Contol + D to get the error, else it hangs.

I was able to recreate this in a Rails project from scratch: https://github.com/vemv/fork_break_bug_repro

It doesn't affect whether one is using fork_break master, or the commit from yesterday for #13. I also tried different things and couldn't get the code to work.

In the real project in which I am using fork_break, fork_break runs generally fine, but I think I found a subtle bug which I'm attempting to recreate in isolation. Maybe that bug and this bug are the same.

Cheers - Victor

pedrocarrico commented 8 years ago

I don't think this one is relate to fork_break at all and from what I see it will be harder to debug.

My current hypothesis here is that when running the rails console (or runner) the data marshalling capabilities of Fork somehow do not work.

I'll try to investigate a little bit further.

vemv commented 8 years ago

Thank you!

I added to my repo a rake task, which also exhibits this bug.

Maybe I made some silly error... can you check my individual commits? They're small/clean.

zeitnot commented 8 years ago

I have the same problem.

pedrocarrico commented 8 years ago

@zeitnot Is it while running rails runner?

Unfortunately Rails runner wraps some objects with bindings so they cannot be marshalled.

Some objects cannot be dumped: if the objects to be dumped include bindings, procedure or method objects, instances of class IO, or singleton objects, a TypeError will be raised.

- http://ruby-doc.org/core-2.1.0/Marshal.html