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

ConnectionFactory lacks a configuration option for closing the DataSource #3141

Open
ppkarwasz opened this issue Oct 29, 2024 · 2 comments
Open
Labels
appenders:JDBC Issue concerning the JDBC appender

Comments

@ppkarwasz
Copy link
Contributor

While the ConnectionFactory connection source is the easiest way to implement custom connection sources, it currently does not provide an option to close the DataSource.

The closure of a DataSource created by ConnectionFactory must be done via external means.

@ppkarwasz ppkarwasz added the appenders:JDBC Issue concerning the JDBC appender label Oct 29, 2024
@garydgregory
Copy link
Member

I don't understand the problem. You allocate a resource, you close the resouce, like in PoolingDriverConnectionSourceTest.openAndClose(PoolingDriverConnectionSource).

Do we have an example or a test that leaks resources?

@ppkarwasz
Copy link
Contributor Author

You can look at the HikariCP example I provided in #3128:

  • I have a static LoggingDataSource.newInstance() method that creates a new DataSource each time it is called.
  • The static method can be easily used together with FactoryMethodConnectionSource and the JDBC appender.
  • When the Log4j configuration is stopped, however, DataSource.close() is not called and the connection pool does not deallocate its resources.

Of course the problem is not in Log4j Core itself and it could be solved by other means, but it would be useful to have a closeOnStop attribute that could be used together with the ConnectionFactory element:

<ConnectionFactory class="eu.copernik.spring.boot.LoggingDataSource"
                   method="newInstance"
                   closeOnStop="true"/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
appenders:JDBC Issue concerning the JDBC appender
Projects
None yet
Development

No branches or pull requests

2 participants