graphql-platform icon indicating copy to clipboard operation
graphql-platform copied to clipboard

[Regression] Multi-threaded access to discover types throws "The given key was not present in the dictionary" exception

Open vypsim opened this issue 1 year ago • 10 comments

Product

Hot Chocolate

Version

15.1.4

Steps to reproduce

When upgrading from HotChocolate v15.1.3 to v15.1.4 we started encountering an issue with our integration tests.

To give you a bit background, we use WebApplicationFactory with parallel test execution.

After upgrading to v15.1.4 whenever the tests are run in parallel, random tests fail with the same error message in the log below, but with random different fields (sometimes for the same test).

I wonder if this is some sort of a race condition or locking that's changed which is causing multiple threads to access the same dictionary during setup.

Apologies for not providing a re-production, but it's a hard scenario to re-produce, I was hoping you might have some ideas based on the changes that went between those 2 versions.

Can you please advise.

Thanks.

What is expected?

For the tests to run without HotChocolate erroring out.

What is actually happening?

HotChocolate is erroring out.

Relevant log output

Message: 
  HotChocolate.SchemaException : For more details look at the `Errors` property.
  
  1. The given key 'System.String id' was not present in the dictionary. (Beacon.API.Assets.GraphQL.QueryType)
  

Stack Trace: 
  TypeInitializer.DiscoverTypes()
  TypeInitializer.Initialize()
  Setup.InitializeTypes(SchemaBuilder builder, IDescriptorContext context, IReadOnlyList`1 types)
  Setup.Create(SchemaBuilder builder, LazySchema lazySchema, IDescriptorContext context)
  SchemaBuilder.Create(IDescriptorContext context)
  ISchemaBuilder.Create(IDescriptorContext context)
  RequestExecutorResolver.CreateSchemaAsync(ConfigurationContext context, RequestExecutorSetup setup, RequestExecutorOptions executorOptions, IServiceProvider schemaServices, TypeModuleChangeMonitor typeModuleChangeMonitor, CancellationToken cancellationToken)
  RequestExecutorResolver.CreateSchemaServicesAsync(ConfigurationContext context, RequestExecutorSetup setup, TypeModuleChangeMonitor typeModuleChangeMonitor, CancellationToken cancellationToken)
  RequestExecutorResolver.CreateRequestExecutorAsync(String schemaName, Boolean isInitialCreation, CancellationToken cancellationToken)
  RequestExecutorResolver.GetRequestExecutorAsync(String schemaName, CancellationToken cancellationToken)  RequestExecutorResolver.WarmupAsync.__WarmupSchemaAsync|40_0(string schemaName, System.Threading.CancellationToken cancellationToken)	Unknown
  RequestExecutorResolver.WarmupAsync(System.Threading.CancellationToken cancellationToken)	Unknown
  RequestExecutorWarmupService.StartAsync(System.Threading.CancellationToken cancellationToken)

Additional context

No response

vypsim avatar Jul 09 '25 02:07 vypsim

In case this helps:

Same issue, same stack trace, with v15.1.7 Only happens for TypeExtension classes. Fluent/Code-first seems unaffected.

Zarium avatar Jul 15 '25 19:07 Zarium

Same here, same story.

stella-yessensei avatar Jul 21 '25 12:07 stella-yessensei

I'm having the same issue, but in my case I was only having issues with enums, some things that I found that might or not help.

I have a query -> resolver -> subresolver. In my first resolver I have getthings([GraphQLType(typeof(ListType<NonNullType<EnumType<MyEnum>>>))] List<MyEnum> values)

Adding something like this was enough for the first resolver.

public class MyEnumType : EnumType<MyEnum>
    {
        protected override void Configure(IEnumTypeDescriptor<MyEnum> descriptor)
        {
            descriptor.BindValuesExplicitly();

            descriptor.Value(ProductCatalogFacetType.Monday);
        }
    }

.AddType<MyEnumType >()

Unfortenally I still have the error in my subresolver.

1. The given key 'System.Collections.Generic.List`1[AnotherEnum] types' was not present in the dictionary. (HotChocolate.Types.ObjectTypeExtension<Presentation.Web.GraphQL.Resolvers.MyResolver>)

at HotChocolate.Configuration.TypeInitializer.DiscoverTypes()
   at HotChocolate.Configuration.TypeInitializer.Initialize()
   at HotChocolate.SchemaBuilder.Setup.InitializeTypes(SchemaBuilder builder, IDescriptorContext context, IReadOnlyList`1 types)
   at HotChocolate.SchemaBuilder.Setup.Create(SchemaBuilder builder, LazySchema lazySchema, IDescriptorContext context)
   at HotChocolate.SchemaBuilder.Create(IDescriptorContext context)
   at HotChocolate.SchemaBuilder.HotChocolate.ISchemaBuilder.Create(IDescriptorContext context)
   at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaAsync(ConfigurationContext context, RequestExecutorSetup setup, RequestExecutorOptions executorOptions, IServiceProvider schemaServices, TypeModuleChangeMonitor typeModuleChangeMonitor, CancellationToken cancellationToken)
   at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaServicesAsync(ConfigurationContext context, RequestExecutorSetup setup, TypeModuleChangeMonitor typeModuleChangeMonitor, CancellationToken cancellationToken)
   at HotChocolate.Execution.RequestExecutorResolver.CreateRequestExecutorAsync(String schemaName, Boolean isInitialCreation, CancellationToken cancellationToken)
   at HotChocolate.Execution.RequestExecutorResolver.GetRequestExecutorAsync(String schemaName, CancellationToken cancellationToken)
   at HotChocolate.Execution.RequestExecutorResolver.<WarmupAsync>g__WarmupSchemaAsync|40_0(String schemaName, CancellationToken cancellationToken)
   at HotChocolate.Execution.RequestExecutorResolver.WarmupAsync(CancellationToken cancellationToken)
   at HotChocolate.AspNetCore.Warmup.RequestExecutorWarmupService.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>b__15_1(IHostedService service, CancellationToken token)

Wraping the enum in a input like this

public class AnotherEnumInput {
    public List<AnotherEnum> another {get;set}
}

The issue seems to go away.

Version 15.1.8

Coelho04 avatar Aug 04 '25 08:08 Coelho04

Having the same issue on 15.1.8.

dkAnBlWo avatar Aug 05 '25 07:08 dkAnBlWo

We fixed this one now on 16.0.0 in milestone 7. We are testing it at the moment to see if its properly fixed. We will port it back in the next couple of days.

michaelstaib avatar Aug 26 '25 07:08 michaelstaib

This one is now merged and will be available in the next 30 mins with version 15.1.9.

michaelstaib avatar Aug 27 '25 10:08 michaelstaib

I'm still having the same issue in versions 15.1.9 and 15.1.10

Coelho04 avatar Sep 08 '25 15:09 Coelho04

This should be fixed with 15.1.11 🎉 Please let us know if you still encounter the issue after upgrading!

tobias-tengler avatar Oct 08 '25 16:10 tobias-tengler

This issue took us a while to figure out, but with the last fix that @tobias-tengler did its finally solved :)

michaelstaib avatar Oct 08 '25 19:10 michaelstaib

@michaelstaib and @tobias-tengler yes it seems fixed thank you.

Coelho04 avatar Oct 09 '25 01:10 Coelho04