100% CPU when revoking tokens
See original GitHub issueConfirm you’ve already contributed to this project or that you sponsor it
- I confirm I’m a sponsor or a contributor
Version
4.x
Describe the bug
My server sometimes goes 100% CPU and I’ve noticed the correlation with 2 logs
The token '{GUID}' was successfully revoked.
and
An exception occurred in the database while saving changes for context type 'Crpg.WebApi.Identity.OpenIddictDbContext'.
Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException: Conflicts were detected for instance of entity type 'OpenIddictEntityFrameworkCoreToken' on the concurrency token properties {'ConcurrencyToken'}. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting values.
at Microsoft.EntityFrameworkCore.InMemory.Storage.Internal.InMemoryTable`1.ThrowUpdateConcurrencyException(IUpdateEntry entry, Dictionary`2 concurrencyConflicts, IDiagnosticsLogger`1 updateLogger)
at Microsoft.EntityFrameworkCore.InMemory.Storage.Internal.InMemoryTable`1.Update(IUpdateEntry entry, IDiagnosticsLogger`1 updateLogger)
at Microsoft.EntityFrameworkCore.InMemory.Storage.Internal.InMemoryStore.ExecuteTransaction(IList`1 entries, IDiagnosticsLogger`1 updateLogger)
at Microsoft.EntityFrameworkCore.InMemory.Storage.Internal.InMemoryDatabase.SaveChangesAsync(IList`1 entries, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(IList`1 entriesToSave, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(StateManager stateManager, Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)""","An exception occurred in the database while saving changes for context type 'Crpg.WebApi.Identity.OpenIddictDbContext'.Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException: Conflicts were detected for instance of entity type 'OpenIddictEntityFrameworkCoreToken' on the concurrency token properties {'ConcurrencyToken'}. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting values. at Microsoft.EntityFrameworkCore.InMemory.Storage.Internal.InMemoryTable`1.ThrowUpdateConcurrencyException(IUpdateEntry entry, Dictionary`2 concurrencyConflicts, IDiagnosticsLogger`1 updateLogger) at Microsoft.EntityFrameworkCore.InMemory.Storage.Internal.InMemoryTable`1.Update(IUpdateEntry entry, IDiagnosticsLogger`1 updateLogger) at Microsoft.EntityFrameworkCore.InMemory.Storage.Internal.InMemoryStore.ExecuteTransaction(IList`1 entries, IDiagnosticsLogger`1 updateLogger) at Microsoft.EntityFrameworkCore.InMemory.Storage.Internal.InMemoryDatabase.SaveChangesAsync(IList`1 entries, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(IList`1 entriesToSave, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(StateManager stateManager, Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
Here are the logs filtering on “OpenIddict” or “error”: openiddict-logs.csv.
For info, I’m using the in-memory provider. I’m thinking that maybe the token revocation expects an index so it’s super slow with this provider?
To reproduce
Hard to reproduce. Use this program and make it run for days https://github.com/verdie-g/crpg/blob/844795b4c2b6c32431a4ff6bf75ce938a9a9d72e/src/WebApi/Program.cs
Exceptions (if any)
No response
Issue Analytics
- State:
- Created 3 months ago
- Comments:15 (15 by maintainers)
Top Results From Across the Web
Introduce a more efficient way to revoke all the tokens ...
Introduce a more efficient way to revoke all the tokens associated with an authorization #1856. Open. 1 task done ... 100% CPU when...
Read more >CancellationTokenSource High Cpu Usage
I am trying to cancel my tasks but it creating high cpu usage. My cpu goes to 100% ... Token); Thread.Sleep(100); } }));...
Read more >100% CPU usage with nothing running : r/techsupport
100 % cpu in task manager when actual tasks only add up to about 30%. Things are very slow to load and it...
Read more >TokenBroker services causes high CPU utilization?
We have been able to isolate the high CPU to the Token Broker service by using the Windows Performance Recorder and Analyzer.
Read more >CPU usage is very high
If the level of CPU use is very high, the response times typically become longer for the end user, but the system still...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@verdie-g makes a lot of sense (tho’ it’s not clear to me why only a single user seems to be affected).
Given it’s likely not an OpenIddict issue at this point, I’m going to close this ticket. I opened https://github.com/openiddict/openiddict-core/issues/1856 to track adding new store methods in 5.0 to make the token chain revocation process much more efficient.
Cheers.
No, the replay detection/revocation mechanism only kicks in when using an authorization code or refresh token (i.e not when using the client credentials grant)