-
-
Notifications
You must be signed in to change notification settings - Fork 520
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
Race condition with MySql #1658
Comments
Hi, Thanks for the report.
It's not technically a race condition:
And as you can see, all the async calls are properly awaited: the enumerator moves to the next value in the sequence only when the token has been revoked. What's likely happening here is that during the call to What's interesting is that I'm not aware of a similar issue with SQL Server. Maybe the SQL provider is smart enough to use different connections to handle that? The only way to solve that - without introducing new one-shot manager/store methods (e.g something like In a future major version, introducing a |
Hi, I did not mean it as race condition of c# or tasks themselves. But as a race condition of
Yes, that's exactly what is happening. Every DbContext (for Pomelo) is using one
Yes, that's where
Can you explain it more? I do not really understand what you mean by that. After understanding, I can prepare a PR on Monday. There is also a workaround (use |
That sounds like a bug/design issue to me. It's not clear why a second connection is not automatically used when the first one is busy. Don't they have a connection pool mechanism? 😕
The first OpenIddict 3.x previews depended on openiddict-core/sandbox/OpenIddict.Sandbox.AspNetCore.Server/Helpers/AsyncEnumerableExtensions.cs Lines 5 to 24 in 5e54e9b
(note: RX development pretty much halted, which would be a major concern if we decided to depend on it in future versions of OpenIddict)
It's the ability to generate Given that support for both set-based/bulk deletes and updates has been added to EF Core 7.0 (dotnet/efcore#795), I'll open a separate thread to track updating the
While SQL Server remains the most popular option, MySQL+Pomelo is a combo I see quite often, so it likely deserves a built-in mitigation. I'll just patch the server event handler that uses this API to buffer the tokens before revoking them and consider it done 😅 |
@trejjam workaround merged. Any chance you could give the 4.1.0 nightly builds a try to confirm it fixed your issue? Thanks. |
Confirm you've already contributed to this project or that you sponsor it
Version
4.x
Describe the bug
Hi,
I may be hitting a race condition while revoking tokens in
OpenIddictServerHandlers.Protection.cs:ValidateTokenEntry.HandleAsync.TryRevokeChainAsync
.We are using a MySql server, as an adapter, we are using
Pomelo
, and pomelo is usingMySqlConnector
.I do not really know the caller, but at the same time, I did not find another invocation than this:
I believe that the issue is caused by using
AsAsyncEnumerable - inside FindByAuthorizationIdAsync
which results in forbidden code:(see https://mysqlconnector.net/troubleshooting/connection-reuse/)
Fix should be simple, do not use
await foreach
when we modify fetched data (we use https://www.nuget.org/packages/System.Linq.Async for that).Or more complex, with introducing a flag passed to
FindByAuthorizationIdAsync
controlling ifAsAsyncEnumerable
orToListAsync
is used. This one is dirtier in my opinion but does not require third-party lib.To reproduce
I will craft one if needed.
Exceptions (if any)
And stacktrace:
The text was updated successfully, but these errors were encountered: