Skip to content

Commit

Permalink
Fixed deadlock when loading the gateway configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Jul 3, 2023
1 parent a558f1b commit 90746df
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public FileConfigurationSession(IObserver<GatewayConfiguration> observer, string
{
_observer = observer;
_fileName = fileName;

BeginLoadConfig();

var fullPath = Path.GetFullPath(fileName);
var directory = Path.GetDirectoryName(fullPath);

Expand Down Expand Up @@ -86,7 +89,6 @@ private void BeginLoadConfig()
catch(Exception ex)
{
_observer.OnError(ex);
_observer.OnCompleted();
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using HotChocolate.Fusion.Configuration;
using HotChocolate.Fusion.Metadata;
using HotChocolate.Language;
using HotChocolate.Utilities;
using static System.Threading.Tasks.TaskCreationOptions;

namespace Microsoft.Extensions.DependencyInjection;
Expand All @@ -31,18 +30,28 @@ public GatewayConfigurationTypeModule(
config =>
{
_configuration = config.Document;
_ready.TrySetResult();

if (!_ready.Task.IsCompletedSuccessfully)
{
_ready.TrySetResult();
}

OnTypesChanged();
},
error => _ready.TrySetException(error),
_ => { },
() => _ready.TrySetCanceled());
}

internal override async ValueTask ConfigureAsync(
ConfigurationContext context,
CancellationToken cancellationToken)
{
await _ready.Task.WaitAsync(cancellationToken).ConfigureAwait(false);
if (!_ready.Task.IsCompletedSuccessfully)
{
await _ready.Task.WaitAsync(cancellationToken)
.WaitAsync(TimeSpan.FromSeconds(5), cancellationToken)
.ConfigureAwait(false);
}

if (_configuration is null)
{
Expand All @@ -60,7 +69,7 @@ internal override async ValueTask ConfigureAsync(
ApplyConfiguration(context.SchemaBuilder, config);
}

private void ApplyConfiguration(ISchemaBuilder schemaBuilder, DocumentNode config)
private static void ApplyConfiguration(ISchemaBuilder schemaBuilder, DocumentNode config)
{
var rewriter = new FusionGraphConfigurationToSchemaRewriter();
var fusionGraphConfig = FusionGraphConfiguration.Load(config);
Expand Down

0 comments on commit 90746df

Please sign in to comment.