Skip to content

Fix memory leak in Concurrent/ThreadSafeLocalContextProvider#8969

Merged
headius merged 4 commits intojruby:jruby-9.4from
headius:contextprovider_leak_fix
Aug 20, 2025
Merged

Fix memory leak in Concurrent/ThreadSafeLocalContextProvider#8969
headius merged 4 commits intojruby:jruby-9.4from
headius:contextprovider_leak_fix

Conversation

@headius
Copy link
Member

@headius headius commented Aug 20, 2025

Re-push of #8483

Uses the Cleaner API to run LocalContext.remove() when a Thread has
terminated, but also eagerly calls all LocalContext.remove() on
terminate().
Cleaner is Java 9+, so it cannot be used on JRuby 9 because that is meant
to run on Java 8 and up.

The disadvantage wrt the Cleaner API is that this will leak a Thread if
`terminate()` is never called. At least it's a Daemon Thread so it doesn't
keep the JVM from exiting.
@headius headius requested a review from enebo August 20, 2025 18:04
@headius headius merged commit a5a19e1 into jruby:jruby-9.4 Aug 20, 2025
193 of 194 checks passed
@headius headius deleted the contextprovider_leak_fix branch August 20, 2025 20:26
@headius headius linked an issue Aug 20, 2025 that may be closed by this pull request
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.

ConcurrentLocalContextProvider leaks memory per thread

2 participants