From 06f2e86c030abd564d989f464f0fe7df303a2a10 Mon Sep 17 00:00:00 2001 From: Andrey Surkov Date: Fri, 10 Jan 2025 16:10:05 +0400 Subject: [PATCH] Fix parallel access to session from GQL fields Fixes #17282 --- .../Resolvers/LockedAsyncFieldResolver.cs | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/OrchardCore/OrchardCore.Apis.GraphQL.Abstractions/Resolvers/LockedAsyncFieldResolver.cs b/src/OrchardCore/OrchardCore.Apis.GraphQL.Abstractions/Resolvers/LockedAsyncFieldResolver.cs index 2a4f42a24e4..85ab7e60be9 100644 --- a/src/OrchardCore/OrchardCore.Apis.GraphQL.Abstractions/Resolvers/LockedAsyncFieldResolver.cs +++ b/src/OrchardCore/OrchardCore.Apis.GraphQL.Abstractions/Resolvers/LockedAsyncFieldResolver.cs @@ -3,21 +3,24 @@ namespace OrchardCore.Apis.GraphQL.Resolvers; -public class LockedAsyncFieldResolver : FuncFieldResolver +public class LockedAsyncFieldResolver : IFieldResolver { - public LockedAsyncFieldResolver(Func> resolver) : base(resolver) - { + private readonly Func> _resolver; + public LockedAsyncFieldResolver(Func> resolver) + { + ArgumentNullException.ThrowIfNull(resolver); + _resolver = resolver; } - public new async ValueTask ResolveAsync(IResolveFieldContext context) + public async ValueTask ResolveAsync(IResolveFieldContext context) { var graphContext = (GraphQLUserContext)context.UserContext; await graphContext.ExecutionContextLock.WaitAsync(); try { - return await base.ResolveAsync(context); + return await _resolver(context).ConfigureAwait(false); } finally { @@ -26,20 +29,24 @@ public LockedAsyncFieldResolver(Func : FuncFieldResolver +public class LockedAsyncFieldResolver : IFieldResolver { - public LockedAsyncFieldResolver(Func, ValueTask> resolver) : base(resolver) + private readonly Func, ValueTask> _resolver; + + public LockedAsyncFieldResolver(Func, ValueTask> resolver) { + ArgumentNullException.ThrowIfNull(resolver); + _resolver = resolver; } - public new async Task ResolveAsync(IResolveFieldContext context) + public async ValueTask ResolveAsync(IResolveFieldContext context) { var graphContext = (GraphQLUserContext)context.UserContext; await graphContext.ExecutionContextLock.WaitAsync(); try { - return await base.ResolveAsync(context); + return await _resolver(context.As()).ConfigureAwait(false); } finally {