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

[#6236] fix(core): fix possible resource leak in BaseCatalog #6253

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,8 @@ public void initAuthorizationPluginInstance(IsolatedClassLoader classLoader) {
LOG.info("Authorization provider is not set!");
return;
}
try {
BaseAuthorization<?> authorization =
BaseAuthorization.createAuthorization(classLoader, authorizationProvider);

try (BaseAuthorization<?> authorization =
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the authorization be closed after creating plugin? Do we need close method? cc @xunliu

Copy link
Member

Choose a reason for hiding this comment

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

I think this change is ok.

Another question is:

Should the authorization be closed after creating plugin? Do we need close method? cc @xunliu

We already closed the authorization plugin in the core/src/main/java/org/apache/gravitino/connector/BaseCatalog.java#L229

  @Override
  public void close() throws IOException {
    if (ops != null) {
      ops.close();
      ops = null;
    }
    if (authorizationPlugin != null) {
      authorizationPlugin.close();
      authorizationPlugin = null;
    }
    if (catalogCredentialManager != null) {
      catalogCredentialManager.close();
      catalogCredentialManager = null;
    }
  }

Copy link
Contributor

Choose a reason for hiding this comment

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

In my opinion, Authorization class is similar to a factory class. It's weird that the factory class has close method.

BaseAuthorization.createAuthorization(classLoader, authorizationProvider)) {
// Load the authorization plugin with the class loader of the catalog.
// Because the JDBC authorization plugin may load JDBC driver using the class loader.
authorizationPlugin =
Expand Down