Skip to content

Disable inline expunge when in computeIfAbsent#18635

Merged
trask merged 3 commits into
open-telemetry:mainfrom
laurit:compute-expunge
May 15, 2026
Merged

Disable inline expunge when in computeIfAbsent#18635
trask merged 3 commits into
open-telemetry:mainfrom
laurit:compute-expunge

Conversation

@laurit

@laurit laurit commented May 8, 2026

Copy link
Copy Markdown
Contributor

Hopefully resolves #18232
An alternative for #18629
#18629 explores removing the inline expunge which is a bit complicated because library instrumentations don't currently use the background thread.

@laurit
laurit marked this pull request as ready for review May 8, 2026 11:21
@laurit
laurit requested a review from a team as a code owner May 8, 2026 11:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR mitigates a reported ConcurrentHashMap deadlock in the weak-key cache implementation by preventing inline expunction from running while a thread is executing a computeIfAbsent mapping function, aligning with the deadlock scenario described in issue #18232.

Changes:

  • Wrap the computeIfAbsent mapping function to track “in compute” state via a per-thread counter.
  • Make expungeStaleEntries() a no-op when invoked from within a computeIfAbsent mapping function to avoid cross-map removal attempts while CHM bins are locked.

Comment on lines 246 to +253
public static void expungeStaleEntries() {
// Skip expunging stale entries if we are inside computeIfAbsent. This check prevents a deadlock
// when there are 2 threads calling computeIfAbsent, that locks the map, and both threads try
// to remove entry from the map locked by the other thread.
// See https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/18232
if (isInComputeIfAbsent()) {
return;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a test, but it isn't 100% reliable at reproducing the original issue.

@laurit laurit added this to the v2.28.0 milestone May 12, 2026
@trask
trask merged commit 51a1cd7 into open-telemetry:main May 15, 2026
261 of 267 checks passed
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.

Deadlock in nightly test

3 participants