Skip to content

Commit 90746df

Browse files
committed
Fixed deadlock when loading the gateway configuration.
1 parent a558f1b commit 90746df

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/HotChocolate/Fusion/src/Core/DependencyInjection/GatewayConfigurationFileObserver.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public FileConfigurationSession(IObserver<GatewayConfiguration> observer, string
3232
{
3333
_observer = observer;
3434
_fileName = fileName;
35+
36+
BeginLoadConfig();
37+
3538
var fullPath = Path.GetFullPath(fileName);
3639
var directory = Path.GetDirectoryName(fullPath);
3740

@@ -86,7 +89,6 @@ private void BeginLoadConfig()
8689
catch(Exception ex)
8790
{
8891
_observer.OnError(ex);
89-
_observer.OnCompleted();
9092
}
9193
});
9294

src/HotChocolate/Fusion/src/Core/DependencyInjection/GatewayConfigurationTypeModule.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using HotChocolate.Fusion.Configuration;
55
using HotChocolate.Fusion.Metadata;
66
using HotChocolate.Language;
7-
using HotChocolate.Utilities;
87
using static System.Threading.Tasks.TaskCreationOptions;
98

109
namespace Microsoft.Extensions.DependencyInjection;
@@ -31,18 +30,28 @@ public GatewayConfigurationTypeModule(
3130
config =>
3231
{
3332
_configuration = config.Document;
34-
_ready.TrySetResult();
33+
34+
if (!_ready.Task.IsCompletedSuccessfully)
35+
{
36+
_ready.TrySetResult();
37+
}
38+
3539
OnTypesChanged();
3640
},
37-
error => _ready.TrySetException(error),
41+
_ => { },
3842
() => _ready.TrySetCanceled());
3943
}
4044

4145
internal override async ValueTask ConfigureAsync(
4246
ConfigurationContext context,
4347
CancellationToken cancellationToken)
4448
{
45-
await _ready.Task.WaitAsync(cancellationToken).ConfigureAwait(false);
49+
if (!_ready.Task.IsCompletedSuccessfully)
50+
{
51+
await _ready.Task.WaitAsync(cancellationToken)
52+
.WaitAsync(TimeSpan.FromSeconds(5), cancellationToken)
53+
.ConfigureAwait(false);
54+
}
4655

4756
if (_configuration is null)
4857
{
@@ -60,7 +69,7 @@ internal override async ValueTask ConfigureAsync(
6069
ApplyConfiguration(context.SchemaBuilder, config);
6170
}
6271

63-
private void ApplyConfiguration(ISchemaBuilder schemaBuilder, DocumentNode config)
72+
private static void ApplyConfiguration(ISchemaBuilder schemaBuilder, DocumentNode config)
6473
{
6574
var rewriter = new FusionGraphConfigurationToSchemaRewriter();
6675
var fusionGraphConfig = FusionGraphConfiguration.Load(config);

0 commit comments

Comments
 (0)