Skip to content

PARQUET-1368: ParquetFileReader should close its input stream for the failure in constructor#510

Merged
rdblue merged 1 commit intoapache:masterfrom
HyukjinKwon:resource-closing
Aug 7, 2018
Merged

PARQUET-1368: ParquetFileReader should close its input stream for the failure in constructor#510
rdblue merged 1 commit intoapache:masterfrom
HyukjinKwon:resource-closing

Conversation

@HyukjinKwon
Copy link
Copy Markdown
Member

This PR proposes to close the stream open in ParquetFileReader's constructor when it throws an error when it is used (readFooter), which causes a resource leak. Otherwise, looks there's no way to close it outside.

For more details, please see the JIRA ticket https://issues.apache.org/jira/browse/PARQUET-1368.

@HyukjinKwon HyukjinKwon changed the title PARQUET-1310: ParquetFileReader should close its input stream for the failure in constructor PARQUET-1368: ParquetFileReader should close its input stream for the failure in constructor Aug 3, 2018
this.footer = readFooter(file, options, f, converter);
try {
this.footer = readFooter(file, options, f, converter);
} catch (Exception e) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why catch the exception and rethrowing it instead of closing the stream in finally?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In that case, this will always be closed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, ok, sorry. Next time I should read the comment in the PR before asking silly questions.

By the way, isn't this a problem in the other constructors in this class, and shouldn't we extend the scope of this try-catch until the end of the constructor? I guess if filterRowGroups throws an exception for some reason, then it could result in unclosed streams too no?

Copy link
Copy Markdown
Member Author

@HyukjinKwon HyukjinKwon Aug 6, 2018

Choose a reason for hiding this comment

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

Ah, it's fine. It took me a while before I reply since that's a common pattern.

I was thinking about that too. Can the same thing happen in other constructors? I thought other constructors are fine since other constructors look not directly using the stream and deprecated.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure if any exception could happen in other constructors, but in my opinion in this case it would make sense to wrap the entire constructor body in try-catch blocks like you did. @gszadovszky what do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think any other code paths need this change, unless I missed something.

I'm not following the logic of expanding the try-catch blocks. I'm going to go ahead and merge this. If we want to follow up with more fixes, lets do that in other issues. Thanks, everyone!

Copy link
Copy Markdown
Contributor

@zivanfi zivanfi Aug 7, 2018

Choose a reason for hiding this comment

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

I agree with Nandor. Creating a Closable object in a constructor means that if anything throws an exception (a RuntimeException possibly) in the rest of the constructor, the Closable won't be closed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Makes sense. Do you want to follow this up with a patch to expand the try/catch?

@HyukjinKwon
Copy link
Copy Markdown
Member Author

Let me also cc @rdblue as well who's also active in Spark side.

@rdblue
Copy link
Copy Markdown
Contributor

rdblue commented Aug 7, 2018

+1

@rdblue rdblue merged commit 45e3ce5 into apache:master Aug 7, 2018
@HyukjinKwon
Copy link
Copy Markdown
Member Author

Thanks guys!

@dongjoon-hyun
Copy link
Copy Markdown
Member

Thank you, @HyukjinKwon !

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.

5 participants