From 852eeb1dd0fe87431717409a856fd605236776d2 Mon Sep 17 00:00:00 2001 From: Andrey Surkov Date: Mon, 13 Jan 2025 19:30:14 +0400 Subject: [PATCH] Fix parallel access to session from GQL fields (#17332) 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 {