Skip to content

fix: avoid deadlock when changeNamespaces joins a populated shared informer - #3655

Open
csviri wants to merge 1 commit into
mainfrom
fix/change-namespaces-deadlock
Open

csviri wants to merge 1 commit into
mainfrom
fix/change-namespaces-deadlock

Conversation

@csviri

@csviri csviri commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Fabric8 replays an already populated informer's cache to a newly added
handler synchronously, on the registering thread. changeNamespaces
registered the handler on an informer starter thread while the event
source held its monitor waiting for that thread, so the replay blocked
on the monitor and deadlocked. Register the handlers on the calling
thread and only start the informers in parallel.

Fixes #3650

Summary by CodeRabbit

  • Bug Fixes
    • Improved namespace changes for active informers when cached events are replayed during handler registration.
    • Newly added namespaces are watched, and events from them can be handled without the namespace change hanging.
    • Informer startup now proceeds reliably when joining an already populated namespace, allowing replayed events to reach their handlers.
  • Tests
    • Added regression coverage confirming the namespace change completes within 10 seconds and delivers the replayed event.

Copilot AI balanced review requested due to automatic review settings October 22, 2026 13:19
@openshift-ci
openshift-ci Bot requested review from metacosm and xstefank October 22, 2026 13:19
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ 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: 2afc4ca9-428c-493d-bd92-b8425d9ba631
📥 Commits

Reviewing files that changed from the base of the PR and between e6bb598 and 72e7bbc.

📒 Files selected for processing: 2
  • operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerManager.java
  • operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSourceNamespaceChangeTest.java

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📝 Walkthrough

changeNamespaces now prepares namespace informer wrappers before executor tasks start them. A regression test covers synchronous cache replay during a namespace change and checks that the new namespace is watched and its event is handled.

Changes: Namespace changes

Layer / File(s) Summary
Informer startup and cache replay
operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerManager.java, operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSourceNamespaceChangeTest.java
changeNamespaces creates and registers namespace wrappers before submitting them to the executor. The test simulates synchronous replay of an existing resource during handler registration and checks that the namespace change completes, the namespace is watched, and the event handler receives an event.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 72e7b

The namespace-change deadlock path is covered by the new test, with no actionable merge-blocking risk identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the primary change: preventing a deadlock when changeNamespaces joins a populated shared informer.
Linked Issues check Passed Issue #3650 requires namespace changes to complete when a new namespace joins a populated shared informer, while preserving event delivery and normal stop behavior. `InformerManager.changeNamespaces()…
Out of Scope Changes check Passed The changes remain within issue #3650. The production change only moves handler registration before parallel informer startup and updates related task logging. The test adds deadlock regression covera…
Full details: Linked Issues check

Explanation

Issue #3650 requires namespace changes to complete when a new namespace joins a populated shared informer, while preserving event delivery and normal stop behavior. InformerManager.changeNamespaces() now creates each InformerWrapper and registers its handler on the calling thread before it waits for parallel informer startup. The regression test simulates synchronous cache replay, applies the namespace change with a timeout, verifies the new namespace and event delivery, and stops the event source.

Full details: Out of Scope Changes check

Explanation

The changes remain within issue #3650. The production change only moves handler registration before parallel informer startup and updates related task logging. The test adds deadlock regression coverage and refactors shared informer setup for that coverage. No unrelated change is demonstrated.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • 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.

🟢 Approval recommended

The focused fix removes the reported lock cycle, preserves lifecycle synchronization and parallel startup, and includes targeted regression coverage.

No open issues 🎉

What changed in this PR

Fixes #3650 by avoiding a deadlock when changeNamespaces() joins a populated shared informer in the core event-source runtime.

Changes:

  • Registers handlers on the calling thread so synchronous cache replay can reenter the event-source monitor.
  • Keeps informer startup parallel.
  • Adds a regression test that simulates synchronous cache replay and verifies namespace changes complete and deliver an event.
File Description
operator-framework-core/​src/​test/​java/​io/​javaoperatorsdk/​operator/​processing/​event/​source/​informer/​ManagedInformerEventSourceNamespaceChangeTest.java Adds deadlock regression coverage and shared test helpers.
operator-framework-core/​src/​main/​java/​io/​javaoperatorsdk/​operator/​processing/​event/​source/​informer/​InformerManager.java Moves handler registration before parallel informer startup.

Review effort: Balanced

…former

Fabric8 replays an already populated informer's cache to a newly added
handler synchronously, on the registering thread. changeNamespaces
registered the handler on an informer starter thread while the event
source held its monitor waiting for that thread, so the replay blocked
on the monitor and deadlocked. Register the handlers on the calling
thread and only start the informers in parallel.

Fixes #3650
@csviri
csviri force-pushed the fix/change-namespaces-deadlock branch from e6bb598 to 72e7bbc Compare October 22, 2026 14:33

This branch has not been deployed

No deployments
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.

ChangeNamespaces deadlocks when joining a populated shared informer

2 participants