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

Merged
RE
3mo ago
+344-1

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