Skip to content

Fix #12771: remove KeystoreEncryptionSpi Cipher ThreadLocal on stop and after use - #13582

Open
arimu1 wants to merge 1 commit into
apache:masterfrom
arimu1:fix/12771-keystore-threadlocal
Open

Fix #12771: remove KeystoreEncryptionSpi Cipher ThreadLocal on stop and after use#13582
arimu1 wants to merge 1 commit into
apache:masterfrom
arimu1:fix/12771-keystore-threadlocal

Conversation

@arimu1

@arimu1 arimu1 commented Sep 13, 2026

Copy link
Copy Markdown

Summary

  • Clear aesWithPadding and aesWithoutPadding static ThreadLocal<Cipher> entries in spiStop() and after each encrypt/decrypt path so worker threads do not retain JCA Cipher instances (and associated providers) after use.
  • Add KeystoreEncryptionSpiSelfTest.testCipherThreadLocalsRemovedAfterUse to verify ThreadLocal entries are refreshed after crypto operations and SPI stop.

Problem

KeystoreEncryptionSpi caches Cipher instances in static ThreadLocals but never called remove(). Long-lived threads (e.g. embedded Tomcat workers) could keep references to Cipher/provider classes and pin the webapp classloader, leading to metaspace OOM on redeploy. spiStop() alone only clears the calling thread.

Test plan

  • ./mvnw -pl modules/core test -Dtest=org.apache.ignite.spi.encryption.KeystoreEncryptionSpiSelfTest (JBR 17, Maven MAVEN_OPTS with Ignite --add-opens flags from parent POM)

Fixes #12771

Remove static Cipher ThreadLocal entries after crypto operations and in
spiStop to avoid pinning classloaders on long-lived worker threads.

Fixes apache#12771
@arimu1
arimu1 force-pushed the fix/12771-keystore-threadlocal branch from feccf98 to 69f2a44 Compare September 13, 2026 00:57
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.

[BUG] ClassLoader Leak / Metaspace OOM: Unmanaged static ThreadLocal<Cipher> in KeystoreEncryptionSpi

1 participant