forked from OrchardCMS/OrchardCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(OrchardCMS#16069):
InvalidOperationException
thrown in `QueryAl…
…iasIndex` when `ISession` is still in "connecting" state
- Loading branch information
1 parent
36a8446
commit e430f6b
Showing
3 changed files
with
33 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/OrchardCore.Modules/OrchardCore.Alias/Services/AliasPartContentHandleHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using OrchardCore.Alias.Indexes; | ||
using OrchardCore.ContentManagement; | ||
using YesSql; | ||
|
||
namespace OrchardCore.Alias.Services | ||
{ | ||
internal sealed class AliasPartContentHandleHelper | ||
{ | ||
private static readonly SemaphoreSlim _yesSqlLock = new(1, 1); | ||
|
||
#pragma warning disable CA1862 // Use the 'StringComparison' method overloads to perform case-insensitive string comparisons | ||
internal static async Task<ContentItem> QueryAliasIndexAsync(ISession session, string alias) | ||
{ | ||
// NOTE: YesSql/Dapper does not support parallel or concurrent requests. | ||
// Doing so can cause an `InvalidOperationException`, with the connection stuck within a "connecting" state. | ||
await _yesSqlLock.WaitAsync(); | ||
try | ||
{ | ||
return await session.Query<ContentItem, AliasPartIndex>(x => x.Alias == alias.ToLowerInvariant()).FirstOrDefaultAsync(); | ||
} | ||
finally | ||
{ | ||
_yesSqlLock?.Release(); | ||
} | ||
} | ||
#pragma warning restore CA1862 // Use the 'StringComparison' method overloads to perform case-insensitive string comparisons | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters