Azure / static-web-apps

Azure Static Web Apps. For bugs and feature requests, please create an issue in this repo. For community discussions, latest updates, kindly refer to the Discussions Tab. To know what's new in Static Web Apps, visit https://aka.ms/swa/ThisMonth
https://aka.ms/swa
MIT License
318 stars 53 forks source link

azure function + cancelation token = The operation was canceled. Cancellation Token has expired: True. #1466

Closed drma-tech closed 1 month ago

drma-tech commented 1 month ago
The operation was canceled.\r\nCancellation Token has expired: True. 
Learn more at: https://aka.ms/cosmosdb-tsg-request-timeout
\r\n
CosmosDiagnostics: 
{\"Summary\":{\"GatewayCalls\":{\"(200, 0)\":2,\"(304, 0)\":1}},\"name\":\"Typed FeedIterator ReadNextAsync\",\"start datetime\":\"2024-05-04T14:11:10.677Z\",\"duration in milliseconds\":291.9556,\"data\":{\"Client Configuration\":{\"Client Created Time Utc\":\"2024-05-04T14:11:09.6217857Z\",\"MachineId\":\"hashedMachineName:4ae0625c-df42-87b4-fe26-c5cf73b3b7fd\",\"NumberOfClientsCreated\":1,\"NumberOfActiveClients\":1,\"ConnectionMode\":\"Direct\",\"User Agent\":\"cosmos-netstandard-sdk/3.38.1|1|X64|Microsoft Windows 10.0.20348|.NET 8.0.1|N|\",\"ConnectionConfig\":{\"gw\":\"(cps:50, urto:6, p:False, httpf: False)\",\"rntbd\":\"(cto: 5, icto: -1, mrpc: 30, mcpe: 65535, erd: True, pr: ReuseUnicastPort)\",\"other\":\"(ed:False, be:False)\"},\"ConsistencyConfig\":\"(consistency: NotSet, prgns:[], apprgn: )\",\"ProcessorCount\":2},\"Query Correlated ActivityId\":\"6b73906f-8fe9-421b-895a-f5fccb085a11\"},\"children\":[{\"name\":\"Create Query Pipeline\",\"duration in milliseconds\":260.4479,\"children\":[{\"name\":\"Get Container Properties\",\"duration in milliseconds\":182.6597,\"children\":[{\"name\":\"Get Collection Cache\",\"duration in milliseconds\":0.5024,\"children\":[{\"name\":\"Waiting for Initialization of client to complete\",\"duration in milliseconds\":0.0457}]},{\"name\":\"Read Collection\",\"duration in milliseconds\":163.3746,\"data\":{\"Client Side Request Stats\":{\"Id\":\"AggregatedClientSideRequestStatistics\",\"ContactedReplicas\":[],\"RegionsContacted\":[],\"FailedReplicas\":[],\"AddressResolutionStatistics\":[],\"StoreResponseStatistics\":[],\"HttpResponseStats\":[{\"StartTimeUTC\":\"2024-05-04T14:11:10.7157817Z\",\"DurationInMs\":121.5808,\"RequestUri\":\"https://sd-cosmos-centralus.documents.azure.com/dbs/dev/colls/main\",\"ResourceType\":\"Collection\",\"HttpMethod\":\"GET\",\"ActivityId\":\"9d6b0faa-150f-4f65-a240-c2e12b2fda6c\",\"StatusCode\":\"OK\"}]}}}]}]},{\"name\":\"Get Partition Key Ranges\",\"duration in milliseconds\":38.2753,\"children\":[{\"name\":\"Try Get Overlapping Ranges\",\"duration in milliseconds\":32.8163,\"data\":{\"PKRangeCache Info(#2024-05-04T14:11:10.9350489Z)\":{\"Previous Continuation Token\":null,\"Continuation Token\":\"\\\"82\\\"\"}},\"children\":[{\"name\":\"Read PartitionKeyRange Change Feed\",\"duration in milliseconds\":7.165,\"data\":{\"Client Side Request Stats\":{\"Id\":\"AggregatedClientSideRequestStatistics\",\"ContactedReplicas\":[],\"RegionsContacted\":[],\"FailedReplicas\":[],\"AddressResolutionStatistics\":[],\"StoreResponseStatistics\":[],\"HttpResponseStats\":[{\"StartTimeUTC\":\"2024-05-04T14:11:10.9122096Z\",\"DurationInMs\":4.3244,\"RequestUri\":\"https://sd-cosmos-centralus.documents.azure.com/dbs/3VIiAA==/colls/3VIiAKq+V+0=/pkranges\",\"ResourceType\":\"PartitionKeyRange\",\"HttpMethod\":\"GET\",\"ActivityId\":\"efeed335-a9d6-452f-b7f7-c87874edcdfb\",\"StatusCode\":\"OK\"}]}}},{\"name\":\"Read PartitionKeyRange Change Feed\",\"duration in milliseconds\":4.2523,\"data\":{\"Client Side Request Stats\":{\"Id\":\"AggregatedClientSideRequestStatistics\",\"ContactedReplicas\":[],\"RegionsContacted\":[],\"FailedReplicas\":[],\"AddressResolutionStatistics\":[],\"StoreResponseStatistics\":[],\"HttpResponseStats\":[{\"StartTimeUTC\":\"2024-05-04T14:11:10.9263370Z\",\"DurationInMs\":3.999,\"RequestUri\":\"https://sd-cosmos-centralus.documents.azure.com/dbs/3VIiAA==/colls/3VIiAKq+V+0=/pkranges\",\"ResourceType\":\"PartitionKeyRange\",\"HttpMethod\":\"GET\",\"ActivityId\":\"3ed17646-1c92-41d4-bf3b-2b44988b2d72\",\"StatusCode\":\"NotModified\",\"ReasonPhrase\":\"Not Modified\"}]}}}]}]},{\"name\":\"[,FF) move next\",\"duration in milliseconds\":11.1162,\"children\":[{\"name\":\"Microsoft.Azure.Cosmos.Handlers.RequestInvokerHandler\",\"duration in milliseconds\":1.7132,\"children\":[{\"name\":\"Get Collection Cache\",\"duration in milliseconds\":0.0075}]}]},{\"name\":\"CosmosOperationCanceledException\",\"duration in milliseconds\":0.0098,\"data\":{\"Operation Cancelled Exception\":\"System.OperationCanceledException: The operation was canceled.\\r\\n   
at System.Threading.CancellationToken.ThrowOperationCanceledException()\\r\\n   
at System.Threading.CancellationToken.ThrowIfCancellationRequested()\\r\\n   
at Microsoft.Azure.Cosmos.Common.CollectionCache.ResolveByNameAsync(String apiVersion, String resourceAddress, Boolean forceRefesh, ITrace trace, IClientSideRequestStatistics clientSideRequestStatistics, CancellationToken cancellationToken)\\r\\n   
at Microsoft.Azure.Cosmos.ContainerCore.GetCachedContainerPropertiesAsync(Boolean forceRefresh, ITrace trace, CancellationToken cancellationToken)\\r\\n   
at Microsoft.Azure.Cosmos.Handlers.RequestInvokerHandler.SendAsync(String resourceUriString, ResourceType resourceType, OperationType operationType, RequestOptions requestOptions, ContainerInternal cosmosContainerCore, FeedRange feedRange, Stream streamPayload, Action`1 requestEnricher, ITrace trace, CancellationToken cancellationToken)\\r\\n   
at Microsoft.Azure.Cosmos.CosmosQueryClientCore.ExecuteItemQueryAsync(String resourceUri, ResourceType resourceType, OperationType operationType, FeedRange feedRange, QueryRequestOptions requestOptions, AdditionalRequestHeaders additionalRequestHeaders, SqlQuerySpec sqlQuerySpec, String continuationToken, Int32 pageSize, ITrace trace, CancellationToken cancellationToken)\\r\\n   
at Microsoft.Azure.Cosmos.Pagination.NetworkAttachedDocumentContainer.MonadicQueryAsync(SqlQuerySpec sqlQuerySpec, FeedRangeState`1 feedRangeState, QueryPaginationOptions queryPaginationOptions, ITrace trace, CancellationToken cancellationToken)\\r\\n   
at Microsoft.Azure.Cosmos.Pagination.PartitionRangePageAsyncEnumerator`2.MoveNextAsync(ITrace trace)\\r\\n   
at Microsoft.Azure.Cosmos.Query.Core.Pipeline.OptimisticDirectExecutionQuery.OptimisticDirectExecutionQueryPipelineStage.OptimisticDirectExecutionQueryPipelineImpl.MoveNextAsync(ITrace trace)\\r\\n   
at Microsoft.Azure.Cosmos.Query.Core.Monads.TryCatch`1.TryAsync[T](Func`2 onSuccess)\\r\\n   
at Microsoft.Azure.Cosmos.Query.Core.Pipeline.OptimisticDirectExecutionQuery.OptimisticDirectExecutionQueryPipelineStage.MoveNextAsync(ITrace trace)\\r\\n   
at Microsoft.Azure.Cosmos.Query.Core.Pipeline.LazyQueryPipelineStage.MoveNextAsync(ITrace trace)\\r\\n   
at Microsoft.Azure.Cosmos.Query.Core.Pipeline.NameCacheStaleRetryQueryPipelineStage.MoveNextAsync(ITrace trace)\\r\\n   
at Microsoft.Azure.Cosmos.Query.Core.Pipeline.CatchAllQueryPipelineStage.MoveNextAsync(ITrace trace)\\r\\n   
at Microsoft.Azure.Cosmos.Query.QueryIterator.ReadNextAsync(ITrace trace, CancellationToken cancellationToken)\"}}]}

For a long time, I thought this was a cosmos problem, but I stopped today to analyze it better, and from what I understand this is an azure function problem. cosmos db is only reacting to the fact that the token is expired, which is a direct consequence of the azure function (it is probably being turned off). Then I ask myself, why is it being turned off, if there is still a function being called and being executed? I ask this here, because the azure function is automatically integrated into the static web app.