Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CosmosDiagnostics throws IndexOutOfRangeException #2075

Closed
LiDamon opened this issue Dec 17, 2020 · 5 comments · Fixed by #2099
Closed

CosmosDiagnostics throws IndexOutOfRangeException #2075

LiDamon opened this issue Dec 17, 2020 · 5 comments · Fixed by #2099
Labels
bug Something isn't working Diagnostics Issues around diagnostics and troubleshooting needs-investigation QUERY

Comments

@LiDamon
Copy link

LiDamon commented Dec 17, 2020

We want get count about all partition with special filter, but have an error
Message:System.AggregateException: One or more errors occurred. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Microsoft.Azure.Cosmos.CosmosDiagnosticsContextCore.d__42.MoveNext()
at System.Collections.Generic.List1.InsertRange(Int32 index, IEnumerable1 collection)
at Microsoft.Azure.Cosmos.CosmosDiagnosticsContextCore.AddDiagnosticsInternal(CosmosDiagnosticsContext newContext)
at Microsoft.Azure.Cosmos.Query.QueryIterator.d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Cosmos.FeedIteratorCore1.<ReadNextAsync>d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Test.CosmosIndexDocService.<>c__DisplayClass34_0.<<GetCount>b__0>d.MoveNext() in C:\CosmosIndexDocService.cs:line 980 --- End of inner exception stack trace --- at Test.CosmosIndexDocService.GetCount() in C:\CosmosIndexDocService.cs:line 993 at CosmosService.SPIndexService.GetUserGranPermissionCount() in C:\SPIndexService.cs:line 2284 at Test.GetSensitivityCount(String tenantId, String logonName, String dorid, DataModule module, SensitiveLevel sensitiveLevel, MemberType type) in C:\\AggUsersRelation.cs:line 409 at GetUseGroupAccess(UsersRelationInfo user, MemberType type) in C:\Aggregate\AggUsersRelation.cs:line 285 ---> (Inner Exception #0) System.IndexOutOfRangeException: Index was outside the bounds of the array. at Microsoft.Azure.Cosmos.CosmosDiagnosticsContextCore.<GetEnumerator>d__42.MoveNext() at System.Collections.Generic.List1.InsertRange(Int32 index, IEnumerable1 collection) at Microsoft.Azure.Cosmos.CosmosDiagnosticsContextCore.AddDiagnosticsInternal(CosmosDiagnosticsContext newContext) at Microsoft.Azure.Cosmos.Query.QueryIterator.<ReadNextAsync>d__11.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.Cosmos.FeedIteratorCore1.d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Test.CosmosIndexDocService.<>c__DisplayClass34_0.

Environment summary
SDK Version:3.15.0
OS Version Windows
.NET Version:4.7.2

@j82w j82w added bug Something isn't working Diagnostics Issues around diagnostics and troubleshooting needs-investigation labels Dec 17, 2020
@j82w
Copy link
Contributor

j82w commented Dec 17, 2020

@LiDamon any chance you can provide a simple console app that reproduce the issue? If not can you please provide the query, query request options, and any other custom settings you have configured for the SDK?

@LiDamon
Copy link
Author

LiDamon commented Dec 18, 2020

This is my code

CosmosClientOptions options = new CosmosClientOptions
{
AllowBulkExecution = true,
ConnectionMode = Microsoft.Azure.Cosmos.ConnectionMode.Direct,
RequestTimeout = TimeSpan.FromMinutes(3),
MaxRetryAttemptsOnRateLimitedRequests = 19,
MaxRetryWaitTimeOnRateLimitedRequests = TimeSpan.FromMinutes(3),
};

public int GetCount()
{

        var queryText = @"SELECT value count(1) FROM c where c.schema=10 and c.type=128 and c.module=2 
                and c.inherittype=1 and c.dorid='42dd7df6-e706-44b1-ba4f-5f9a9bf6342d'";
        var query = new QueryDefinition(queryText);
        var options = new QueryRequestOptions
        {
            MaxConcurrency = 100000,
            MaxBufferedItemCount = 1,
            MaxItemCount = 1
        };
        using (var queryIterator = container.GetItemQueryIterator<Int32>(query, null, options))
        {
            while (queryIterator.HasMoreResults)
            {
                var queryTask = Task.Run(async () => await queryIterator.ReadNextAsync());
                queryTask.Wait(TimeSpan.FromMinutes(10));
                if (queryTask.Result.Count == 1)
                {
                    return queryTask.Result.FirstOrDefault();
                }
            }
        }
        return 0;
    }

This is index json

image

BTW , we before used 3.12 don't found this issue. Upgrade to 3.15 found it. So we plan downgrade to 3.12

@j82w j82w added the QUERY label Dec 21, 2020
@LiDamon
Copy link
Author

LiDamon commented Dec 23, 2020

I add retry logic, Won't show up exception the second time. But this error occurs very frequently.

@j82w j82w changed the title Use Count occur an exception CosmosDiagnostics throws IndexOutOfRangeException Dec 29, 2020
@j82w
Copy link
Contributor

j82w commented Dec 29, 2020

@LiDamon what is the reason for doing the Task.Run? Why not just use a cancellation token with a timeout?

@LiDamon
Copy link
Author

LiDamon commented Jan 1, 2021

@j82w j82w closed this as completed in #2099 Jan 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Diagnostics Issues around diagnostics and troubleshooting needs-investigation QUERY
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants