-
Notifications
You must be signed in to change notification settings - Fork 41.5k
Description
Hi,
following up on the registration of JDBC drivers in Spring Boot (especially #2612).
As I can see it, no Spring Boot Application (e.g. 2.2.6) deregisters its JDBC driver.
Standard Spring Boot created with Spring boot initializr & In Memory H2 database, will leave its driver behind, which leads to a memory leak as the class loader cannot be GCed.
Why is there no huge outcry?
- Running with an embedded tomcat does not show the problem as it is anyway restarted
- Running in a stand-alone tomcat does not show the problem (or only a warning) as the memory leak detection of tomcat will take care of it, just logging a severe log message (https://stackoverflow.com/questions/3320400/to-prevent-a-memory-leak-the-jdbc-driver-has-been-forcibly-unregistered)
I guess these are the most standard cases, but if you run it in a JBoss environment you will not have much fun as the server will quickly rise an OOM after some deployments.
Workaround (which I deployed) is to deregister the driver in a context listener, when the context is destroyed (much like https://stackoverflow.com/questions/3320400/to-prevent-a-memory-leak-the-jdbc-driver-has-been-forcibly-unregistered/23912257#23912257).
Sure, we could relay on the Tomcat memory leak protection or deploy the database driver in the application server, but I would assume a War-file produced by Spring Boot should run everywhere.
What is your take on it?
Best