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

Demonstrate race condition to discuss how to fix #91 #94

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

Conversation

themodernlife
Copy link
Contributor

I was kind of glad to see #91, because I too have ran into this issue while processing LZO files (from S3) via Spark using local config with multiple threads.

I dug into this and the issue seems to be in

CodecPool.returnDecompressor(decompressor);
.

When using Spark, the exception occurs because the TextInputFormat creates a LineRecordReader that loads the decompressor from the pool. When it gets closed, the LineRecordReader adds it back to the pool... the trouble is that underlying LzopInputStream also adds the decompressor back to the pool, which means the same decompressor is now in the pool twice.

This means that the next 2 calls to getRecordReader are going to use the same decompressor, and that's where you get the race condition.

I attached a unit test that demonstrates the error. The fix here is just to remove the bit that adds the decompressor back to the pool on 349.

Can someone have a look at this as well and let me know what you think? I can clean up the PR and resubmit, but just wanted to add some info about the bug.

Cheers!

@sjlee
Copy link
Collaborator

sjlee commented Sep 28, 2014

Thanks for the report @themodernlife. We'll look into it.

@themodernlife
Copy link
Contributor Author

Hey gang, just wondering if you guys have any feedback on this?

@sjlee
Copy link
Collaborator

sjlee commented Nov 5, 2014

We haven't been able to spend much time on this. At the high level we recognize the issue, but it might be tricky/expensive to fix as users may have code written to work around this and we shouldn't break them...

public class LzopDecompressor extends LzoDecompressor {
private static final Log LOG = LogFactory.getLog(LzopDecompressor.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used?

@rangadi
Copy link
Contributor

rangadi commented Nov 6, 2014

sorry, can you point to the fix? I must be missing obvious.

@sjlee
Copy link
Collaborator

sjlee commented Nov 6, 2014

@rangadi, this particular pull request was just to demonstrate the bug itself. I think @themodernlife's suggestion is to not pool decompressors (which he added and commented out in this PR).

@sjlee
Copy link
Collaborator

sjlee commented Nov 6, 2014

If we simply remove the line that returns the decompressor in LzopInputStream.close(), it would satisfy the use cases mentioned here (via LineRecordReader, or any use case that returns the decompressor). However, I'm pretty certain there are a lot of use cases (correct or not) that are not returning the decompressor, implicitly relying on LzopInputStream.close(). For them, the decompressors would start leaking.

As you suggested, annotating the decompressor as DoNotPool is one option, but we would forgo the benefit of pooling. Decompressors carry native buffers, and not pooling them would have a fairly major performance implication depending on the use cases. So I'm not sure we want to go there.

BTW, it looks like the compressor (LzopOutputStream) has the same issue.

@sjlee
Copy link
Collaborator

sjlee commented Dec 5, 2014

Now that #103 was merged, would you like to clean up this unit test and update this PR? This would be a useful test.

@CLAassistant
Copy link

CLAassistant commented Jul 18, 2019

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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