{"record":{"id":"cff09971ee2f898f","repo":"OrchardCMS/OrchardCore","slug":"an-error-occurred-while-pruning-authorizations","errorCode":null,"errorMessage":"An error occurred while pruning authorizations.","messagePattern":"An error occurred while pruning authorizations\\.","errorType":"exception","errorClass":"AggregateException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdTokenStore.cs","lineNumber":373,"sourceCode":"\n            try\n            {\n                await _session.FlushAsync(cancellationToken);\n            }\n            catch (Exception exception)\n            {\n                exceptions ??= new List<Exception>(capacity: 1);\n                exceptions.Add(exception);\n\n                continue;\n            }\n\n            result += tokens.Count;\n        }\n\n        if (exceptions != null)\n        {\n            throw new AggregateException(\"An error occurred while pruning authorizations.\", exceptions);\n        }\n\n        return result;\n    }\n\n    /// <inheritdoc/>\n    public virtual async ValueTask<long> RevokeAsync(\n        string subject, string client, string status, string type, CancellationToken cancellationToken)\n    {\n        Expression<Func<OpenIdTokenIndex, bool>> query = index => true;\n\n        if (!string.IsNullOrEmpty(subject))\n        {\n            Expression<Func<OpenIdTokenIndex, bool>> filter = index => index.Subject == subject;\n\n            query = Expression.Lambda<Func<OpenIdTokenIndex, bool>>(\n                Expression.AndAlso(query.Body, filter.Body), query.Parameters[0]);\n        }","sourceCodeStart":355,"sourceCodeEnd":391,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdTokenStore.cs#L355-L391","documentation":"OpenIdTokenStore.PruneAsync deletes expired tokens in batches and aggregates any per-batch exceptions. If at least one batch failed, it throws an AggregateException titled 'An error occurred while pruning authorizations.' containing all underlying failures. Note the message mentions authorizations but is thrown by the token store, a copy-paste artifact in the source.","triggerScenarios":"Calling PruneAsync (via ITokenStore.PruneAsync, usually from the OpenIddict pruning background task) when deleting expired tokens throws — e.g., YesSql database errors, concurrency conflicts, or query failures during batch removal.","commonSituations":"Database connectivity issues or timeouts during the periodic cleanup job; a concurrent transaction modifying a token being pruned; YesSql storage backend misconfiguration on a specific tenant; large backlogs of expired tokens making batches hit lock/timeout limits.","solutions":["Inspect the InnerExceptions of the AggregateException to find the actual root cause (DB timeout, concurrency, connectivity).","Re-run the prune operation; it is idempotent since it only deletes expired tokens.","Verify database health and YesSql store configuration for the tenant running the background task.","Reduce prune batch pressure by ensuring pruning runs regularly (avoid huge expired-token backlogs) and check tenant logs in App_Data/Sites/{Tenant}/logs for details."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    await tokenStore.PruneAsync(date, ct);\n}\ncatch (AggregateException ex)\n{\n    foreach (var inner in ex.InnerExceptions)\n        logger.LogError(inner, \"Token prune batch failed\");\n    // pruning is idempotent; schedule a retry\n}","preventionTips":["Run the prune background task regularly so expired-token batches stay small.","Check tenant database connectivity and YesSql configuration before enabling pruning at scale.","Inspect InnerExceptions rather than the aggregate message for root cause.","Watch tenant logs under App_Data/Sites/{Tenant}/logs for recurring storage errors."],"tags":["database","background-task","openid","maintenance"],"backgroundTag":"database-query-failed","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}