Skip to content

Add XDECREF for returned read tuple in ReadParser.read_pair_iterator()#693

Merged
ctb merged 8 commits into
masterfrom
fix/read-memleak
Dec 17, 2014
Merged

Add XDECREF for returned read tuple in ReadParser.read_pair_iterator()#693
ctb merged 8 commits into
masterfrom
fix/read-memleak

Conversation

@mr-c

@mr-c mr-c commented Dec 16, 2014

Copy link
Copy Markdown
Contributor

Pull request for #692

@mr-c

mr-c commented Dec 16, 2014

Copy link
Copy Markdown
Contributor Author

@camillescott thank you for finding this and providing a fix

@mr-c

mr-c commented Dec 16, 2014

Copy link
Copy Markdown
Contributor Author
  • minimal test for memory leak (doesn't have to be a nose test)

@camillescott

Copy link
Copy Markdown
Member

@mr-c: easiest way is to run:

import khmer
rp = khmer.ReadParser('large-paired-fasta.fa')
for pair in rp.iter_read_pairs():
    pass

Observe memory usage while it runs, and the leak will be obvious. Call del rp and nothing happens. Note that this is only an issue with the paired version, as it gives the Read references to a tuple before returning them.

@mr-c

mr-c commented Dec 16, 2014

Copy link
Copy Markdown
Contributor Author

I can confirm the memory and the fix

@mr-c

mr-c commented Dec 16, 2014

Copy link
Copy Markdown
Contributor Author

I get

terminate called after throwing an instance of 'khmer::read_parsers::NoMoreReadsAvailable'
  what():  Generic khmer exception
Aborted (core dumped)

After testing without the fix. This is inelegant, looking into that now.

@camillescott

Copy link
Copy Markdown
Member

ReadParser throws that exception when it runs out of reads, presumably to mimic a Python iterator (for reasons I'm not entirely sure of).

Is it only throwing that when multiple threads are in use? 'Cause it looks like the CPython iterator isn't thread-safe: there's a race condition there if another thread depletes the parser after checking is_complete(), which I believe will allow that exception to propagate.

Potential solution: catch the NoMoreReadsAvailable exception in the try block on line 409, which avoids another lock.

@mr-c

mr-c commented Dec 16, 2014

Copy link
Copy Markdown
Contributor Author

This was just the test code above. So single-threaded?

@mr-c

mr-c commented Dec 16, 2014

Copy link
Copy Markdown
Contributor Author

@camillescott and I have fixed the segfault that we inadvertently found due to a corrupted file in @ctb homedir.

@mr-c

mr-c commented Dec 16, 2014

Copy link
Copy Markdown
Contributor Author

Bonus: I've removed the unused callback code which has increased our code coverage.

  • Is it mergable?
  • Did it pass the tests?
  • If it introduces new functionality in scripts/ is it tested?
    Check for code coverage.
  • Is it well formatted? Look at make pep8, make diff_pylint_report,
    make cppcheck, and make doc output. Use make format and manual
    fixing as needed.
  • Did it change the command-line interface? Only additions are allowed
    without a major version increment. Changing file formats also requires a
    major version number increment.
  • Is it documented in the ChangeLog?
  • Was a spellchecker run on the source code and documentation after
    changes were made?

@camillescott

Copy link
Copy Markdown
Member

Not to rain on the code-axing parade, but some of that callback stuff is potentially useful for me.

@mr-c

mr-c commented Dec 16, 2014

Copy link
Copy Markdown
Contributor Author

I'll split that into another PR for a proper discussion.

@mr-c

mr-c commented Dec 16, 2014

Copy link
Copy Markdown
Contributor Author

which means I'll be force pushing to this branch in a moment, do beware!

@mr-c

mr-c commented Dec 16, 2014

Copy link
Copy Markdown
Contributor Author

branch force done.

@mr-c

mr-c commented Dec 17, 2014

Copy link
Copy Markdown
Contributor Author

Ready for review & merge @ctb @camillescott @luizirber

@ctb

ctb commented Dec 17, 2014

Copy link
Copy Markdown
Member

Looks good to me; merging.

ctb added a commit that referenced this pull request Dec 17, 2014
Add XDECREF for returned read tuple in ReadParser.read_pair_iterator()
@ctb ctb merged commit 246c85e into master Dec 17, 2014
@ctb

ctb commented Dec 17, 2014

Copy link
Copy Markdown
Member

Actually, I missed the wonky ChangeLog formatting. @mr-c, can this be fixed?

@mr-c mr-c deleted the fix/read-memleak branch December 30, 2014 17:56
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.

4 participants