Skip to content

Remove static ThreadLocal caching in XmlUtils to prevent ClassLoader leaks#2516

Open
jbonofre wants to merge 1 commit intoapache:mainfrom
jbonofre:fix/xmlutils-threadlocal-classloader-leak
Open

Remove static ThreadLocal caching in XmlUtils to prevent ClassLoader leaks#2516
jbonofre wants to merge 1 commit intoapache:mainfrom
jbonofre:fix/xmlutils-threadlocal-classloader-leak

Conversation

@jbonofre
Copy link
Copy Markdown
Member

@jbonofre jbonofre commented Apr 5, 2026

The static ThreadLocal fields holding DocumentBuilderFactory, TransformerFactory and SAXParserFactory pin the ClassLoader of the XML provider bundle on long-lived Karaf worker threads. When that bundle is updated or refreshed, the old ClassLoader can never be GC'd, causing zombie bundles and Metaspace growth.

This patch removes the ThreadLocal caching and creates fresh factory instances per call. The public API is unchanged.

Fixes #2278

…leaks

The static ThreadLocal fields holding DocumentBuilderFactory, TransformerFactory
and SAXParserFactory pin the ClassLoader of the XML provider bundle on long-lived
Karaf worker threads. When that bundle is updated or refreshed, the old
ClassLoader can never be GC'd, leading to zombie bundles and Metaspace growth.

Create fresh factory instances per call instead of caching them. The public API
is unchanged.

Fixes apache#2278
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 5, 2026

Test Results

233 files  ±0  233 suites  ±0   21m 54s ⏱️ +2s
917 tests ±0  869 ✅ ±0  48 💤 ±0  0 ❌ ±0 
921 runs  ±0  873 ✅ ±0  48 💤 ±0  0 ❌ ±0 

Results for commit 9160869. ± Comparison against base commit 031d9a1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ClassLoader leak and "Zombie Bundles" caused by static ThreadLocals in XmlUtils

1 participant