Skip to content

Don't cache LibrarySearcher's index wrappers in thread-locals - #9894

Merged
headius merged 1 commit into
jruby:jruby-10.0from
matrei:fix/library-searcher-wrappers
Oct 27, 2026
Merged

headius merged 1 commit into
jruby:jruby-10.0from
matrei:fix/library-searcher-wrappers

Conversation

@matrei

@matrei matrei commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Part of #9781, against jruby-10.0 for the 10.0 LTS line.

LibrarySearcher cached its key and range wrappers for the loaded features index in per-runtime ThreadLocals. Their values stay in every thread that used the runtime after it is torn down. StringWrapper is a JRuby class, so a pooled thread keeps the class loader that loaded JRuby alive until its ThreadLocalMap happens to expunge the stale entry. tearDown() can't clear them, because ThreadLocal.remove() only removes the calling thread's value.

They've been thread-locals since 0e7f4d4, before the index was locked; ced903e made all their accessors synchronized three weeks later. The wrappers are only used inside the synchronized withKeyWrapper and withRangeWrapper, so they are now plain fields. Accesses are serialized by the searcher's lock, as before. A nested call on the same thread shares the wrapper, just as it shared the thread-local one.

rake spec:ji passes (974 examples, 0 failures, 9 pending). rake spec:ruby:fast has 1 failure and 4 errors, all IPv6 socket specs that fail the same way on unmodified jruby-10.0, because my machine has no IPv6 network.

The key and range wrappers for the loaded features index were cached in
per-runtime ThreadLocals. Their values stay in every thread that used
the runtime after it is torn down, and since StringWrapper is a JRuby
class, a pooled thread keeps the class loader that loaded JRuby alive.

The wrappers are only used while holding the searcher's lock, so they
are now plain fields.
@headius headius added this to the JRuby 10.0.8.0 milestone Oct 27, 2026

@headius headius left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good comments to hopefully keep future edits from breaking this synchronization invariant. Approved.

@headius
headius merged commit 54589c3 into jruby:jruby-10.0 Oct 27, 2026
127 checks passed
@matrei
matrei deleted the fix/library-searcher-wrappers branch October 27, 2026 20:45
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.

2 participants