Message-ID: From: "embuc (@embuc)" To: "pgjdbc/pgjdbc" Date: Tue, 09 Jan 2024 13:56:41 +0000 Subject: [pgjdbc/pgjdbc] issue #3089: Metaspace Memory leak: Thread.inheritedAccessControlContext List-Id: X-GitHub-Author-Id: 1480007 X-GitHub-Author-Login: embuc X-GitHub-Issue: 3089 X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-State: closed X-GitHub-Type: issue X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/issues/3089 Content-Type: text/plain; charset=utf-8 **Describe the issue** After update to driver version > 42.6.0 (tested also both released version up to latest released 42.7.1) we started to notice memory leaks connected to re-deploys of web-apps in Apache Tomcat (ver 9.0.80). I inspected heap dumps and found the instances of org.postgresql.util.LazyCleaner retained in Metaspace i.e. with path to GC roots with excluded phantom/weak/soft/etc references. Regression seem to have happened with release of 42.6.0 version. Downgraded to 42.5.4 - after excessive testing - no leaks in Metaspace and everything was released correctly. Perhaps this has to do something with [fix 2817](https://github.com/pgjdbc/pgjdbc/pull/2817) and/or [fix 2847 ](https://github.com/pgjdbc/pgjdbc/pull/2847)? I didn't have time to investigate more but it should be hopefully enough to point the experts in right direction. **Driver Version?** 42.6.0 **Java Version?** 17 **OS Version?** Ubuntu 22.04 **PostgreSQL Version?** 14 **To Reproduce** Steps to reproduce the behaviour: Re-deploy .war files in Apache Tomcat. **Expected behaviour** GC should be able to clean Metaspace when classes are unloaded (as with deploy). And what actually happens: Old Classloader is bound with reference from LazyCleaner thus preventing GC to remove it. **Logs** If possible PostgreSQL logs surrounding the occurrence of the issue (N/A)