Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Segmentation faults and memory corruption from using libxml-ruby with nokogiri #116
We have been experiencing memory corruption in our Rails application which depends on nokogiri (22.214.171.124) and libxml-ruby (2.8.0). This memory corruption manifested itself in seemingly random segmentation faults with stack traces to nearly every part of code in our application and its dependencies.
After upgrading or removing nearly every gem with a C extension we were able to verify it would go away when we removed a gem that dependent on libxml-ruby. Upon investigation into libxml-ruby segmentation faults we came across similar issues of sparklemotion/nokogiri#895 and sparklemotion/nokogiri#881 and sparklemotion/nokogiri#1364 and #62 . That issue was patched some versions ago, but it appears that a similar issue still exists.
I am able to reproduce on Amazon Linux (RHEL/CentOS based distro) but not on OSX with this script 3/4 of the time it executes.
Here is a sample of the stack traces that result.
We hope to eventually remove our dependency on libxml-ruby as we use nokogiri in our codebase, but a required dependency currently forces libxml-ruby into our project as well. A patch would be great for compatibility and for anyone else that may encounter this convoluted issue. We had to spend a lot of time troubleshooting this issue as none of the segmentation faults that happened in our systems pointed to nokogiri or libxml-ruby.
referenced this issue
Feb 16, 2016
I had the same issue but I went through a journey to find solution.
It started with our Passenger worker jamming and not responding. After a lot of logging and testing we discovered that Passenger jams while we are parsing XML and returns 502 status code and leaves a segmentation fault in logs. We contacted Passenger Development Team, and with their help we concluded that libxml-ruby was the issue. We rewrote our code only to use nokogiri and now it works.
Special thanks to Passenger Development Team.
Note: Wrote this to make it easier for other people with similar issue to find this solution faster.
libxml-ruby, nokogiri, passenger worker jams, xml parsing
@bbergstrom Just in case you're still looking for some reprieve, an application I work on is experiencing extremely similar issues to the ones you have mentioned here (segmentation faults,
Once we finish evaluating the patch I'll be sure to push it upstream and cc you on the pull request to test it out.