DRb recycled objects.

Discussion in 'Ruby' started by Kevin Brown, Nov 3, 2005.

  1. Kevin Brown

    Kevin Brown Guest

    I started this as a question but figured out the answer while I was
    researching, so I'm posting this here for others that may have the same

    The error I received from my code was as follows:

    (druby://*:9000) /usr/lib/ruby/1.8/drb/drb.rb:375:in `_id2ref': 0xdbe53cf6 is
    recycled object (RangeError)
    from (druby://*:9000) /usr/lib/ruby/1.8/drb/drb.rb:375:in `to_obj'
    from (druby://*:9000) /usr/lib/ruby/1.8/drb/drb.rb:1343:in `to_obj'
    from (druby://*:9000) /usr/lib/ruby/1.8/drb/drb.rb:1626:in `to_obj'
    from (druby://*:9000) /usr/lib/ruby/1.8/drb/drb.rb:601:in
    from (druby://*:9000) /usr/lib/ruby/1.8/drb/drb.rb:899:in
    from (druby://*:9000) /usr/lib/ruby/1.8/drb/drb.rb:1453:in
    from (druby://*:9000) /usr/lib/ruby/1.8/drb/drb.rb:1465:in
    from (druby://*:9000) /usr/lib/ruby/1.8/drb/drb.rb:1435:in `perform'
    ... 22 levels...
    from /usr/local/lib/site_ruby/1.8/Qt/qtruby.rb:1040:in
    from /usr/local/lib/site_ruby/1.8/Qt/qtruby.rb:1040:in `exec'
    from /usr/local/lib/site_ruby/1.8/KDE/korundum.rb:395:in `exec'
    from ./init.rb:1123
    KCrash: Application 'init.rb' crashing...

    This was happening consistantly from the same place in the code. I finally
    tracked down the line that was giving me grief, and the issue was that I had
    a method called Order#id. When I was running the code without DRb, this
    worked just fine, but calling id on a DRb proxy object will get you its DRb
    object id. I was returning this value, etc.

    I fixed the problem by changing the method name to order_id, so I know how to
    avoid the error, but I would still like a little more explaination as to why
    exactly this occurred so I can get DRb just that much clearer in my mind. :)
    Kevin Brown, Nov 3, 2005
    1. Advertisements

  2. Kevin Brown

    Hugh Sasse Guest

    You will now run into a problem when you port this to Rails :)

    [Rails uses the method #{name}_id to reference the primary key in table
    "name" (cf Foreign Key)]
    -------------------------------------------------------------- Object#id
    obj.id => fixnum
    Soon-to-be deprecated version of +Object#object_id+.

    uniquely identifies an object in the Ruby process. I'm not sure how
    DRb uses it, but probably to make sure the objects are distinct.Thank you for flagging this up.
    Hugh Sasse, Nov 3, 2005
    1. Advertisements

  3. Kevin Brown

    Eric Hodel Guest

    DRb uses the __id__ of the object and the URL of the process it is
    running on to create a proxy object on other DRb processes.
    Redefining #id to #object_id probably had nothing to do with fixing
    your problem.

    Usually this error comes when a remote DRb process has a reference to
    an object that was garbage collected before the remote process tried
    to access it.
    Eric Hodel, Nov 3, 2005
  4. Kevin Brown

    Richard Dale Guest

    I'm not sure about the cause of your problem.. But as you using Korundum you
    could use DCOP instead of DRB. So I'm interested in what you think are the
    relative merits of using Drb or DCOP for your application.

    -- Richard
    Richard Dale, Nov 3, 2005
  5. Kevin Brown

    Kevin Brown Guest

    We _do not_ want to have to have KDE installed on the server. Much less
    running. :)
    Kevin Brown, Nov 4, 2005
  6. Kevin Brown

    Kevin Brown Guest

    Content-Type: text/plain;
    Content-Transfer-Encoding: 7bit

    Eric, I really REALLY am not trying to point a finger here at ALL, but I guess my question is why did Ruby garbage collect the object consistantly (I mean at least 30 executions in the exact same place)? Where as now that I've axed all the .id calls it consistantly (at least 100 executions) works now.

    Richard and everyone else may also like that I was getting Korundum warnings about Object#id being depracated and to use Object#object_id. These only showed up when I started using DRb. This was what made me change the names in the first place, because it was obvious to me that MY code wasn't getting called. I don't know the Korundum bindings too well, but I'm guessing the Korundum method_missing fired instead of the call being passed across the wire. Perhaps this was a nasty interaction between the two? Korundum object id used instead of a DRb object id which later tried to get passed down the wire? Maybe? There is a lot of two way communication between the server and client.

    Either way, I'm _relatively_ sure that it works now...?

    And this is exactly why I posted, because I still don't get it.

    I do know how to change the garbage collection method for DRb, but I simply haven't had the need at all, since it consistantly works now (I'll continue to monitor).
    Kevin Brown, Nov 4, 2005
  7. Kevin Brown

    Kevin Brown Guest

    Forgot to mention this is only one front end. It is possible (but
    uh...personal yuck there) that we'll have a Windows front end in the future.
    For now we're already going to have both web and KDE front ends, so the
    communication method has to be generic. :)
    Kevin Brown, Nov 4, 2005
  8. Kevin Brown

    Eric Hodel Guest

    The garbage collector is not random in how it collects garbage.
    Which objects are considered garbage can be affected by which methods
    are called.
    You can either rewrite your application to ensure it holds onto all
    remote references or you can use one of the alternate id conversion

    Eric Hodel, Nov 5, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.