Skip to content

fix(streaming): refresh idle EventHub cursors to avoid QueueCacheMissException - #10266

Merged
ReubenBond merged 1 commit into
dotnet:mainfrom
ReubenBond:reubenbond-fix-eventhub-cursor-refresh
Jul 15, 2026
Merged

ReubenBond merged 1 commit into
dotnet:mainfrom
ReubenBond:reubenbond-fix-eventhub-cursor-refresh

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Jul 15, 2026 •

Copy link
Copy Markdown
Member

Problem

Orleans retains inactive stream cursors longer than the EventHub cache retains data and token metadata. When new data wakes an inactive consumer, PersistentStreamPullingAgent.StartInactiveCursors calls cursor.Refresh(startToken) — but EventHub's Cursor.Refresh was an empty no-op. The stale cursor then requested an already-evicted token and threw QueueCacheMissException.

Solution

Add real refresh support to the shared PooledQueueCache:

  • An idle or unset cursor is repositioned to the supplied non-null startToken (the first newly available event) without skipping it. The cursor is reset to Unset before SetCursor so it lands exactly at the token rather than being advanced past it by the idle-skip path.
  • An active (Set) cursor that is mid-enumeration is left untouched.
  • Refresh only ever moves a cursor forward: a cursor already positioned at or ahead of the requested token is left in place rather than rewound, matching SimpleQueueCache's conservatism.
  • A null token is a no-op, preserving the previous behavior on the delivery hot path.

EventHubQueueCache and the EventHub cursor now delegate to PooledQueueCache.Refresh. IEventHubQueueCache.Refresh is added as a default-implemented no-op so external cache implementations of this documented extension point keep compiling.

Tests

  • Cache-level: refreshing an idle cursor after its event and token metadata are purged delivers the new event exactly once without QueueCacheMissException; refresh does not reposition an active cursor; refresh does not rewind a cursor already holding a future token.
  • EventHub: the cursor's Refresh delegates to the underlying cache.
  • Pulling agent: integration test covering the idle -> purge -> new-event wake-up sequence.
Microsoft Reviewers: Open in CodeFlow

…Exception

Orleans retains inactive stream cursors longer than the EventHub cache
retains data and token metadata. When new data woke an inactive consumer,
PersistentStreamPullingAgent called cursor.Refresh(startToken), but the
EventHub cursor's Refresh was an empty no-op. The stale cursor then
requested an evicted token and threw QueueCacheMissException.

This adds real refresh support to the shared PooledQueueCache: an idle or
unset cursor is repositioned to the supplied non-null sequence token (the
first newly available event) without skipping it, while an active (Set)
cursor mid-enumeration is left untouched. Refresh only ever moves a cursor
forward, so a cursor already positioned at or ahead of the requested token
is left in place rather than rewound. EventHubQueueCache and the EventHub
cursor now delegate to it, and IEventHubQueueCache.Refresh is a
default-implemented no-op so external cache implementations keep working.

Regression coverage is added at the cache, EventHub adapter, and
pulling-agent levels, including the idle -> purge -> new-event wake-up
sequence.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 638ef335-61cb-4f6c-8261-c2f778b0f9a6
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

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 addresses a correctness issue in Orleans streaming where inactive EventHub stream cursors can outlive both cached messages and the cache’s token metadata, leading to QueueCacheMissException when an inactive subscription is reactivated. The fix adds concrete “refresh” behavior to PooledQueueCache and wires EventHub’s cursor/cache to use it, with targeted unit/integration tests.

Changes:

  • Added PooledQueueCache.Refresh(...) to reposition idle/unset cursors to a provided start token (no-op for null, and never rewinds/doesn’t move active cursors).
  • Added IEventHubQueueCache.Refresh(...) (default no-op) and delegated EventHubQueueCache/cursor refresh behavior to the underlying pooled cache.
  • Added tests covering idle-cursor refresh after purge, active-cursor non-repositioning, and “no rewind” behavior, plus an EventHub delegation test.
Show a summary per file
File Description
test/Orleans.Streaming.Tests/StreamingTests/PersistentStreamPullingAgentTests.cs Adds an integration-style test reproducing the idle → purge → new-event wake-up scenario using a purgeable pooled cache wrapper.
test/Orleans.Streaming.Tests/OrleansRuntime/Streams/PooledQueueCacheTests.cs Adds cache-level unit tests validating refresh semantics (idle/unset reposition, active no-op, and forward-only behavior).
test/Extensions/Orleans.Streaming.EventHubs.Tests/CheckpointerTests/EventHubCheckpointerTests.cs Adds a test ensuring EventHub cursor Refresh delegates to the EventHub cache.
src/Orleans.Streaming/Common/PooledCache/PooledQueueCache.cs Implements Refresh for pooled-cache cursors with the intended safety rules (no-op for null, don’t move active cursors, don’t rewind).
src/Azure/Orleans.Streaming.EventHubs/Providers/Streams/EventHub/IEventHubQueueCache.cs Adds Refresh as a default-implemented no-op extension point for binary/source compatibility.
src/Azure/Orleans.Streaming.EventHubs/Providers/Streams/EventHub/EventHubQueueCache.cs Delegates Refresh to the underlying PooledQueueCache.
src/Azure/Orleans.Streaming.EventHubs/Providers/Streams/EventHub/EventHubAdapterReceiver.cs Makes EventHub cursor Refresh call into the cache’s refresh implementation.
src/api/Orleans.Streaming/Orleans.Streaming.cs Updates public API surface for PooledQueueCache.Refresh.
src/api/Azure/Orleans.Streaming.EventHubs/Orleans.Streaming.EventHubs.cs Updates public API surface for IEventHubQueueCache.Refresh and EventHubQueueCache.Refresh.

Copilot's findings

  • Files reviewed: 9/9 changed files
  • Comments generated: 0

@ReubenBond
ReubenBond marked this pull request as ready for review July 15, 2026 19:29
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@ReubenBond
ReubenBond merged commit e1e7a28 into dotnet:main Jul 15, 2026
117 of 119 checks passed
@ReubenBond
ReubenBond deleted the reubenbond-fix-eventhub-cursor-refresh branch July 15, 2026 19:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants