Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GC compaction causes segfaults #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

flavorjones
Copy link

@flavorjones flavorjones commented Dec 13, 2022

A few releases of Nokogiri on the v1.13.x branch were to fix Nokogiri when GC compaction happens in Ruby 3.0+.

Something's broken with the xmlsec integration with Nokogiri in this gem which segfaults during compaction / object relocation. I think it's because xmlsec is freeing memory that Nokogiri still has a handle on, leading to dangling pointers that cause a problem when objects are relocated during compaction.

This PR just compacts after each spec to reproduce the issue. I'm not sure how to solve it yet, I need to do a bit more work to fully understand it.

to demonstrate that compaction breaks something between the two
libraries.
@flavorjones
Copy link
Author

@maths22 Can you please kick off CI on this one?

@flavorjones flavorjones changed the title GC compaction breaks xmlsec/nokogiri GC compaction causes segfaults Dec 13, 2022
@maths22
Copy link
Member

maths22 commented Dec 14, 2022

I bet this explains the intermittent segfaults I was randomly getting while working on #16 this afternoon, going off the hypothesis that they only happened if GC happened to run mid-spec run. Thank you for pinning this down better than I could; between me having minimal C-extension-level ruby debugging experience and the segfault only happening occasionally and not happening in CI I was just bewildered.

@flavorjones
Copy link
Author

Short-term, it may be worth telling users to make sure to avoid or disable compaction. I may not get time to look at it this week.

flavorjones added a commit to sparklemotion/nokogiri that referenced this pull request Dec 31, 2022
because that gem doesn't support compaction and frequently segfaults

see instructure/nokogiri-xmlsec-instructure#17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants