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

[Functions] Fix classloader leaks #12973

Merged

Conversation

lhotari
Copy link
Member

@lhotari lhotari commented Nov 25, 2021

Motivation

While investigating error code 143 problems in DataStax Pulsar Helm Chart CI, I noticed that some classloaders are leaked.

Modifications

  • Fix classloader leak in FunctionCommon.getClassLoaderFromPackage
  • Fix classloader leak in SinksImpl and SourcesImpl

Documentation

  • no-need-doc

@lhotari lhotari added type/bug The PR fixed a bug or issue reported a bug release/2.9.1 release/2.8.3 labels Nov 25, 2021
@lhotari lhotari added this to the 2.10.0 milestone Nov 25, 2021
@lhotari lhotari self-assigned this Nov 25, 2021
@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Nov 25, 2021
Copy link
Contributor

@nicoloboschi nicoloboschi left a comment

Choose a reason for hiding this comment

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

LGTM

@jerrypeng
Copy link
Contributor

@lhotari the lines that actually changed in pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/FunctionCommon.java

doesn't seem as much as git is displaying. Is there formatting issue? It is hard to see which lines actually changed.

@lhotari
Copy link
Member Author

lhotari commented Dec 3, 2021

@lhotari the lines that actually changed in pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/FunctionCommon.java

doesn't seem as much as git is displaying. Is there formatting issue? It is hard to see which lines actually changed.

@jerrypeng I don't seem to have that issue in the GitHub Web UI. The diff shows the changes. Which diff tool are you using?

@jerrypeng
Copy link
Contributor

@lhotari I am just using the github Web UI. In FunctionCommon.java is it all that you added was a try / finally that wraps the the existing code in getClassLoaderFromPackage method?

@lhotari
Copy link
Member Author

lhotari commented Dec 3, 2021

@lhotari I am just using the github Web UI. In FunctionCommon.java is it all that you added was a try / finally that wraps the the existing code in getClassLoaderFromPackage method?

@jerrypeng Now I see what you mean. Yes the diff is pretty hard to read. Yes, I wrapped with another try catch where the finally block is

} finally {
    if (!keepJarClassLoader) {
        closeClassLoader(jarClassLoader);
    }
    if (!keepNarClassLoader) {
        closeClassLoader(narClassLoader);
    }
}

@lhotari
Copy link
Member Author

lhotari commented Dec 3, 2021

besides the finally block, I added the lines to set keepNarClassLoader and keepJarClassLoader as needed.

Copy link
Contributor

@jerrypeng jerrypeng left a comment

Choose a reason for hiding this comment

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

@lhotari this LGTM but can you add some unit tests for this?

@lhotari
Copy link
Member Author

lhotari commented Dec 3, 2021

@lhotari this LGTM but can you add some unit tests for this?

@jerrypeng Thanks for reviewing. I can add tests, but the barrier for that is that it feels hard to unit test classloader leaks. Can you recommend an approach for this particular case?

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

LGTM

adding tests is hard in this case.
I am not sure about how to do it.

hooking into Class loading is hard and also it will probably depend on the JVM/Java version.

We could count the calls to "ClassLoaderUtils.closeClassLoader" using PowerMock, but I am not sure it is worth

@lhotari lhotari merged commit cab946b into apache:master Dec 3, 2021
@lhotari lhotari deleted the lh-close-classloaders-sink-source-validation branch December 3, 2021 11:37
lhotari added a commit that referenced this pull request Dec 3, 2021
* Fix classloader leak in FunctionCommon.getClassLoaderFromPackage

* Fix classloader leak in SinksImpl and SourcesImpl

* Fix logic for shouldCloseClassLoader

(cherry picked from commit cab946b)
@lhotari lhotari added the cherry-picked/branch-2.8 Archived: 2.8 is end of life label Dec 3, 2021
lhotari added a commit to datastax/pulsar that referenced this pull request Dec 3, 2021
* Fix classloader leak in FunctionCommon.getClassLoaderFromPackage

* Fix classloader leak in SinksImpl and SourcesImpl

* Fix logic for shouldCloseClassLoader

(cherry picked from commit cab946b)
lhotari added a commit that referenced this pull request Dec 3, 2021
* Fix classloader leak in FunctionCommon.getClassLoaderFromPackage

* Fix classloader leak in SinksImpl and SourcesImpl

* Fix logic for shouldCloseClassLoader

(cherry picked from commit cab946b)
@lhotari lhotari added the cherry-picked/branch-2.9 Archived: 2.9 is end of life label Dec 3, 2021
fxbing pushed a commit to fxbing/pulsar that referenced this pull request Dec 19, 2021
* Fix classloader leak in FunctionCommon.getClassLoaderFromPackage

* Fix classloader leak in SinksImpl and SourcesImpl

* Fix logic for shouldCloseClassLoader
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-picked/branch-2.8 Archived: 2.8 is end of life cherry-picked/branch-2.9 Archived: 2.9 is end of life doc-not-needed Your PR changes do not impact docs release/2.8.2 release/2.9.1 type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants