Closed mattias-palm closed 10 months ago
When an incoming http request is canceled, ASP.NET notifies the request pipeline through the use of cancellation tokens. IdentityServer respects that cancellation by passing the token into the entity framework based store. This causes the database query to be cancelled when it is not needed - which is what we intend - but Entity Framework logs a warning message when it happens. In our use case, this warning isn't helpful because canceled http requests happen occasionally in normal operations (users click the back and stop buttons in their browsers sometimes) and we want to cancel operations when they occur. But this is implanted by EF, not Identity server, so we can't control these warnings directly. You can safely filter them out of your logs though.
Thanks. Do you have any idea where these cancellation tokens could be coming from in this case? It only ever seems to happen within ClientSecretValidator for us and it does so quite often. I don't think it's end users that are doing it.
The code that supplies the cancellation tokens to the EF stores gets its cancellation tokens directly from the http context. Requests might be getting interrupted for any number of reasons, including the user pressing back or stop, but I've also seen badly behaved client applications issue multiple http requests and then cancelling the extras. For example, I've seen the rxjs library do that sort of thing in angular applications when making http requests and processing the results in an observable, and I'm sure other tools are capable of producing extra http requests and then canceling them.
In any event, the cancellation token is definitely coming from the incoming http request. I can see why the pattern of client secret validation would draw your attention. My guess is that the request is being cancelled quickly, and therefor the cancellation appears early in the pipeline. Secret validation is one of the first checks in the pipeline so that seems consistent with your results.
Ok, thanks for your help
Which version of Duende IdentityServer are you using? 6
Which version of .NET are you using? 6
Describe the bug We frequently experience System.OperationCanceledException and System.Threading.Tasks.TaskCanceledExceptions when validating a client with ClientSecretValidator. It doesn't happen every time, but several times a day and more often during busy hours with higher loads. Tasks and operations seem to get canceled while reading the database. Why is this?
To Reproduce I have not found a way to reproduce this.
Expected behavior To not have the tasks and operations canceled.
Log output/exception with stacktrace TaskCanceledException:
OperationCanceledException: