-
Notifications
You must be signed in to change notification settings - Fork 372
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
Logout Notifications can result in concurrent access to underlying DbContext #1627
Comments
@mackie1001 I've moved this to the IdentityServer repo so that it can be picked up by our team to be fixed. |
@mackie1001 As a short term workaround you could override SendLogoutNotificationsAsync in the |
@RolandGuijt Thanks, as it stands now our retry mechanism seems to handle it eventually but we'll consider overriding the implementation in the meantime. Thanks for looking into it. |
Which version of Duende IdentityServer are you using?
7.0.7
Which version of .NET are you using?
8.0.8
Describe the bug
We've observed in our logs occasional exceptions being thrown from within
DefaultBackChannelLogoutService.SendLogoutNotificationsAsync
that relate to multi-threaded access to the operational store DbContext (see stack trace below).This appears to be due to that method doing a
Task.WhenAll
for the collection of logout requests and the code that generates the logout token uses the key management implementation with sometimes needs to fetch the key material from the DB. The concurrent executions all share the instance DbContext and thus the error.To Reproduce
Observed under production load but theoretically:
DefaultBackChannelLogoutService.SendLogoutNotificationsAsync
for said sessionExpected behavior
The implementation is either changed to await each request in turn or the scoping of the underlying services is revised to avoid this situation when executing requests in parallel.
Log output/exception with stacktrace
Additional context
We noticed an increased prevalence of this issue since upgrading to .Net 8. We also had a similar bug in our own code that presented itself much more under the same production load since upgrading. We're putting this down to runtime changes increasing the chance of genuine parallelism when using the Task.WhenAll pattern.
The text was updated successfully, but these errors were encountered: