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

Core: Add finalizer to ResolvingFileIO #7536

Merged
merged 1 commit into from
May 9, 2023

Conversation

nastra
Copy link
Contributor

@nastra nastra commented May 5, 2023

No description provided.

@github-actions github-actions bot added the core label May 5, 2023
@@ -83,21 +90,22 @@ public Map<String, String> properties() {

@Override
public void initialize(Map<String, String> newProperties) {
close(); // close and discard any existing FileIO instances
Copy link
Contributor Author

@nastra nastra May 5, 2023

Choose a reason for hiding this comment

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

@rdblue do you remember why this was necessary? I added a flag for detecting whether close() was already called to be used in the finalize() method. Given that close() is being called here and then later again during a proper close() call, I ended up removing this call here

Copy link
Contributor

Choose a reason for hiding this comment

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

It was just in case initialize was called again. Technically, that invalidates the configuration and we should close/reopen any FileIO instances that are held.

We could just reset isClosed in this method instead of removing this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've reset isClosed here for now but I think we should consider removing this close() call from initialize(..) in a follow-up


@SuppressWarnings("checkstyle:NoFinalizer")
@Override
protected void finalize() throws Throwable {
Copy link
Member

@snazy snazy May 5, 2023

Choose a reason for hiding this comment

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

Sorry @nastra, but stong -100 on using finalize() at all. See JDK-8165641.

Copy link
Contributor

Choose a reason for hiding this comment

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

@snazy, we know.

Iceberg uses this pattern to ensure that close is called. We also log the stack trace at WARN so that we can track down leaks. It is better to close in a finalizer than to not close at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@snazy I agree that finalize() is a pattern we shouldn't rely on, but on Spark executor notes we don't have any other way of closing resources unfortunately

Copy link
Member

@snazy snazy left a comment

Choose a reason for hiding this comment

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

Object.finalize() should really never be overwritten - it causes security and system stability issues.

@nastra nastra force-pushed the add-finalizer-to-resolving-fileio branch from a2a6682 to f54428a Compare May 8, 2023 06:19
@rdblue rdblue merged commit 66bd278 into apache:master May 9, 2023
41 checks passed
@nastra nastra deleted the add-finalizer-to-resolving-fileio branch May 10, 2023 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants