justinmclean opened a new issue, #10604:
URL: https://github.com/apache/gravitino/issues/10604
### What would you like to be improved?
BaseCatalog.close() stops closing resources after the first exception. In
BaseCatalog.java (line 289), ops, authorizationPlugin, and
catalogCredentialManager are closed sequentially, but if ops.close() or
authorizationPlugin.close() throws, the remaining resources are never closed.
This can leave plugin or credential-manager resources leaked during catalog
shutdown.
### How should we improve?
Make BaseCatalog.close() attempt to close all managed resources even if one
fails. A straightforward fix is to catch exceptions for each close operation,
continue closing the remaining resources.
Here's a unit test to help:
```
@Test
void testCloseClosesAllResourcesWhenOpsCloseFails() throws
IllegalAccessException, IOException {
TestCatalog catalog = new TestCatalog();
CatalogOperations ops = Mockito.mock(CatalogOperations.class);
AuthorizationPlugin authorizationPlugin =
Mockito.mock(AuthorizationPlugin.class);
CatalogCredentialManager credentialManager =
Mockito.mock(CatalogCredentialManager.class);
Mockito.doThrow(new IOException("close ops failed")).when(ops).close();
FieldUtils.writeField(catalog, "ops", ops, true);
FieldUtils.writeField(catalog, "authorizationPlugin",
authorizationPlugin, true);
FieldUtils.writeField(catalog, "catalogCredentialManager",
credentialManager, true);
Assertions.assertThrows(IOException.class, catalog::close);
Mockito.verify(authorizationPlugin).close();
Mockito.verify(credentialManager).close();
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]