Repository navigation
Conversation
…gistering one absent from the cache - a failing resource fetcher no longer ends the polling of that resource - a stale scheduled entry is dropped when the primary is not in the cache, so a recreated resource can be registered again Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
There was a problem hiding this comment.
🟡 Changes recommended
A polling-registration race can erase a replacement registration and leave duplicate, uncancellable polling chains, while the timing-dependent regression test can miss the bug.
2 open issues
What changed in this PR
This PR extracts two polling fixes from #3664 to improve recovery in the SDK’s per-resource polling event source without changing its API.
Changes:
- Logs fetcher exceptions and continues scheduling polls.
- Removes stale scheduling entries when a primary resource is absent from the cache, allowing re-registration.
- Adds regression tests for both recovery scenarios.
| File | Description |
|---|---|
operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingEventSourceTest.java |
Adds tests for continued polling and re-registration. |
operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingEventSource.java |
Handles fetch failures and clears missing-resource registrations. |
Review effort: Balanced
| // no new execution is scheduled in this case, an on delete event should be received | ||
| // shortly; | ||
| // the entry is dropped so that it can't block a registration of a recreated resource | ||
| scheduledFutures.remove(primaryID); |
| await() | ||
| .pollDelay(Duration.ofMillis(2 * PERIOD)) | ||
| .untilAsserted(() -> verify(supplier, never()).fetchResources(any())); |


Summary
Two independent fixes in
PerResourcePollingEventSource.FetchingExecutor, extracted from the virtual thread support PR (#3664) so they can be reviewed and merged on their own.1. A failing fetcher no longer stops the polling of a resource
FetchingExecutor.run()calledgetAndCacheResource(...)without any error handling. If theResourceFetcherthrew aRuntimeException,scheduleNextExecution(...)was never reached, so the resource silently stopped being polled until it was deleted and recreated.The exception is now caught and logged, and the next poll is scheduled as usual.
2. A resource absent from the cache can be registered again
When the primary resource is not found in the primary cache,
FetchingExecutorlogs a warning and does not schedule a new execution, but the completedScheduledFuturestayed inscheduledFutures. AsregisterTaskonly registers a resource when there is no entry for it, a recreated resource with the sameResourceIDcould never be registered again.The stale entry is now removed in that case.
Behavior change
log.errorand no longer silently end the polling of the resource.Tests
Added to
PerResourcePollingEventSourceTest:keepsPollingAfterTheFetcherFailed: the first fetch throws, and the test verifies that polling continues (at least 3 fetches).resourceAbsentFromTheCacheCanBeRegisteredAgain: the primary is missing from the cache, then comes back, and the test verifies that the resource is polled after being registered again.PerResourcePollingEventSourceTestpasses (9 tests).