Skip navigation.

Syndicate

Syndicate content

User login

Tricky bug in libxml-ruby 0.5.2

I’ve been playing around with CouchDb, and to that end I’ve been writing a little Ruby app to suck the DMOZ directory database into CouchDb, to see how it performs and get a feel for CouchDb’s idioms.

To do that I was using Libxml-Ruby, which is the closest thing to a performant XML API Ruby has. I ran into an issue using the XML::Reader object, which reads an XML file as a stream of nodes sort of like a pull version of a SAX parser.

I had my test code running great, only it would seemingly at random crash with:

 [BUG] XmlNode Doc is not bound! (ruby_xml_node.c:1270)
 ruby 1.8.6 (2007-06-07) [x86_64-linux]

 Aborted (core dumped)

The odd thing was, the failure report would report this [BUG] message from different source file/line numbers seemingly at random. Because of this, at first I thought it was a problem with the json library I was using, then the xmlsimple library. Eventually I tracked down the ruby_xml_node.c file (part of the libxml-ruby extension as it happens) and looked at line 1270. This falls within the ruby_xml_node_mark_common, which I know from my time in Ruby Garbage Collector Hell is a mark function used by the GC to find out what Ruby objects a given object references, after which it garbage collects any objects that didn’t get ‘marked’. This is clearly the mark function for the XML::Node type.

I’ve posted a bug report to the libxml-devel mailing list here with the details. In the end I pinned this down to repeatable code by forcing a garbage collection after the XML::Reader.expand call, which was creating a Node object without a Document to go with it. The moral of the story is that bugs in GC code are really hard to track down since they can pop up at literally any time, whenever the GC decides to do a garbage collection.

I’ve not found a workaround, so I think I’ll revert to the last stable version of libxml-ruby, 0.3.8.4.