Azure / azure-cosmos-dotnet-v3

.NET SDK for Azure Cosmos DB for the core SQL API
MIT License
723 stars 477 forks source link

ChangeFeedProcessorBuilder throws exception for ChangeFeedMode on 3.39.0 #4423

Closed Blackbaud-IanThomas closed 2 months ago

Blackbaud-IanThomas commented 2 months ago

We are continuously addressing and improving the SDK, if possible, make sure the problem persist in the latest SDK version.

Describe the bug After upgrading to 3.39.0 of the SDK, services using ChangeFeedProcessorBuilder are throwing an exception with the description:

System.ArgumentException: Switching ChangeFeedMode to Incremental Feed is not allowed.

To Reproduce The issue appears to be with services where the lease document is a "legacy document". To reproduce requires a service where the lease document does not have the "Mode" property. Using ChangeFeedProcessorBuilder with the following basic configuration:

_sourceContainer
                    .GetChangeFeedProcessorBuilder<JObject>("ChangeFeed", HandleChangesAsync)
                    .WithInstanceName($"ChangeFeed-{Guid.NewGuid()}")
                    .WithLeaseContainer(_leaseContainer)
                    .Build();

will result in the behavior.

Expected behavior Services with legacy documents for change feed work after upgrade with no required changes.

Actual behavior Services with legacy documents for change feed throw exception and fail to start change feed processor.

Environment summary SDK Version: 3.39.0 OS Version (e.g. Windows, Linux, MacOSX)

Additional context

In exploring the underlying code, it appears that the default ChangeFeedProcessorBuilder is being set to ChangeFeedMode.LatestVersion here, but that is then getting mapped to a value for ChangeFeedIncremental, here. When a legacy document is encountered, the mode is defaulted to LatestVersion here, which doesn't match anymore due to the remapping that took place in between.

ernesto1596 commented 2 months ago

This is a breaking change for our production service.

philipthomas-MSFT commented 2 months ago

Investigation underway. Thanks for your patience: