Skip to content

fix: compute desired states outside of ConcurrentHashMap.computeIfAbsent - #3666

Closed
csviri wants to merge 1 commit into
operator-framework:nextfrom
csviri:fix/desired-state-aspects-reentrancy-next
Closed

csviri wants to merge 1 commit into
operator-framework:nextfrom
csviri:fix/desired-state-aspects-reentrancy-next

Conversation

@csviri

@csviri csviri commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Applying the desired state aspects inside computeIfAbsent failed with
"Recursive update" when an aspect looked up the actual resource of the
dependent (same key) or of another dependent whose key landed in the same
bin. Compute with a lock per dependent instead, and hand the thread already
computing a desired state the state as it is so far.

Co-Authored-By: Claude Sonnet 5.5 noreply@anthropic.com

Applying the desired state aspects inside computeIfAbsent failed with
"Recursive update" when an aspect looked up the actual resource of the
dependent (same key) or of another dependent whose key landed in the same
bin. Compute with a lock per dependent instead, and hand the thread already
computing a desired state the state as it is so far.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 28, 2026 09:31
@coderabbitai

coderabbitai Bot commented Oct 28, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b1ee0052-b0ae-412d-b304-9729326824bf

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

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.

🟡 Changes recommended

Concurrent reciprocal resource lookups can deadlock on per-dependent locks, causing reconciliation to hang indefinitely.

1 open issue
What changed in this PR

This PR addresses recursive-update failures when desired-state aspects look up dependent resources during reconciliation.

Changes:

  • Moves desired-state computation outside ConcurrentHashMap.computeIfAbsent, using per-dependent locks.
  • Returns the in-progress desired state for same-thread aspect re-entry.
  • Adds tests for self-lookups, cross-dependent lookups with colliding hashes, and cached desired-state reuse.
File Description
operator-framework-core/​src/​test/​java/​io/​javaoperatorsdk/​operator/​processing/​dependent/​DesiredStateAspectReentrancyTest.java Adds reentrancy and desired-state caching regression tests.
operator-framework-core/​src/​main/​java/​io/​javaoperatorsdk/​operator/​api/​reconciler/​DefaultContext.java Introduces per-dependent locking and in-progress desired-state tracking.

Review effort: Balanced

Comment on lines +278 to +280
final var lock =
desiredStateLocks.computeIfAbsent(dependentResource, ignored -> new ReentrantLock());
lock.lock();
@csviri csviri closed this Oct 28, 2026
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