Skip to content

fix: ignore change-feed lease-lost errors in event subscriptions - #61

Open
rickykaare wants to merge 1 commit into
mainfrom
fix/ignore-lease-lost
Open

rickykaare wants to merge 1 commit into
mainfrom
fix/ignore-lease-lost

Conversation

@rickykaare

Copy link
Copy Markdown
Contributor

Problem

During rollouts and scale-out, Cosmos change-feed leases are rebalanced between instances. The SDK reports this via the change-feed error notification, either as a CosmosException 412 ("lease token was taken over by owner ...") or as an exception wrapping LeaseLostException ("Lease was lost due to load balancing ..."). Chronicles forwarded these to IEventSubscriptionExceptionHandler, and consumers log them as errors, which creates App Insights noise on every deployment (seen in session-processor and cdr-processor; six Teal services share the same handler pattern).

Change

  • EventDocumentProcessor.ErrorAsync no longer forwards lease-lost errors (a 412 CosmosException or LeaseLostException anywhere in the exception chain). The new lease owner resumes from the last checkpoint, so nothing is lost.
  • ChangeFeedProcessorUserException (exceptions from our own processing code) is always forwarded, even if it wraps a 412.
  • Other IDocumentProcessor implementations are unchanged.
  • CHANGELOG entry under Unreleased.

Tests

5 new tests in EventDocumentProcessorTests (generic error forwarded, non-lease Cosmos error forwarded, 412 ignored, wrapped lease-lost ignored, user exception with 412 forwarded). All 222 tests pass, and the two "ignore" tests fail without the fix.

Lease ownership moving to another instance (scale-out, rollout) is expected and the new owner resumes from the last checkpoint. These errors are no longer forwarded to IEventSubscriptionExceptionHandler.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

Copilot review overview

🟢 Approval recommended

The change is localized, has focused regression coverage, and has no unresolved blocking issues.

Review effort: Balanced
Findings: None

What changed in this PR

Reduces deployment-related error noise by filtering expected Cosmos DB lease-loss notifications in event subscriptions.

Changes:

  • Suppresses lease-loss errors while preserving user-processing error reporting.
  • Adds five focused regression tests.
  • Documents the behavior under Unreleased.
File Description
test/​Chronicles.Tests/​EventStore/​Internal/​EventDocumentProcessorTests.cs Tests error filtering and forwarding.
src/​Chronicles/​EventStore/​Internal/​EventDocumentProcessor.cs Filters expected lease-loss notifications.
CHANGELOG.md Documents the subscription behavior change.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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