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

curtail ASN1 memory leaks #8

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

Conversation

wchristian
Copy link

this was two different leaks rolled into one, which i will explain below. i also have to note the test still leaks some objects, but i don't have the time to do full analysis on that

modules used to diagnose the leaks:
Net::Prometheus, Devel::Gladiator, Devel::FindRef, Devel::Cycle

#1 is the globals in the parser holding on to things

normally deciding when to clean these up could be a little tricky, but the parsing appears to be contained entirely within the _new method, so we can declare them local and have perl reset them at the end of scope

optimally Convert::ASN1 would take care of this so they're deleted after they're needed; as well as instanced per object or creation of new parsers guarded while one is currently active

#2 is PKCS10 creating the object, running ->find on it, which returns a shallow copy with a reference to a config hash in the original object, then puts said shallow copy into the config hash of the original object, which creates a cycle

i don't know whether a deep clone is appropriate there, so i just had the wrapping module weaken the reference to the config hash

@wchristian
Copy link
Author

to be clear on why i'm putting the PR here:

  1. it took me 3 days to get this far and get something workable into the world. Convert::ASN1 could be patched too, but it would be a lot more work for myself to develop a patch in it and i can't reasonably allocate more time currently
  2. i also notified gbarr, and this way there's a decent chance that one of you two gets a patch out :)

@wchristian
Copy link
Author

the weaken resulted in a crash on certain csrs, deep clone seems to fix it, will provide a test and changed fix later

this was two different leaks rolled into one, which i will explain below.
i also have to note the test still leaks *some* objects, but i don't have
the time to do full analysis on that

modules used to diagnose the leaks:
Net::Prometheus, Devel::Gladiator, Devel::FindRef, Devel::Cycle

openxpki#1 is the globals in the parser holding on to things

normally deciding when to clean these up could be a little tricky, but the
parsing appears to be contained entirely within the _new method, so we can
declare them local and have perl reset them at the end of scope

optimally Convert::ASN1 would take care of this so they're deleted after
they're needed; as well as instanced per object or creation of new parsers
guarded while one is currently active

openxpki#2 is PKCS10 creating the object, running ->find on it, which returns a
*shallow* copy with a reference to a config hash in the original object,
then puts said shallow copy into the config hash of the original object,
which creates a cycle

at first i thought weaken would be the more appropriate option here, but
that simply crashed on trying to parse certain certs, so a deep clone is
used and seems to fix the issue
@wchristian
Copy link
Author

updated the patch after trying the previous iteration in our production system

weakening the result of ->find caused crashes in some parses, so i switched it to deep-cloning which also seems to fix the leaks, but doesn't break any parsing as far as i can tell

added a test for that too

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