While debugging some caching code, I’ve come across a segfault related
to ObjectSpace::_id2ref. Apparently it’s returning illegal objects:
Remote Exception: NotImplementedError:
/usr/local/encap/mephle-0.8.0/share/mephle/Driver/Storage_cache.rb:49:in
cache': method
_oid’ called on terminated object (0x4043a568)
The code up to this point:
…
o = ObjectSpace::_id2ref(id)
cache(o)
rescue RangeError …
…
def cache(object)
oid = object._oid # line 49
…
end
It seems that somehow, it’s returning a bad object, or the object is
getting collected after the fact, or something. I’m checking for
RangeError, and this isn’t getting raised. I tried GC.start
and Thread.critical=true, around this block. Same deal.
Sometimes it outright segfaults.
So far, I haven’t been able to reproduce this with a tiny script.
However, I have been able to confirm that it is getting collected, by
checking the id’s via a finalizer. So _id2ref is somehow returning
a collected object.
Not using _id2ref isn’t really an option; it’s critical to maintaining
integrity, so I can’t really get around using it.