From 61468343d64e3d774f012e76e231a4cc3fafedd4 Mon Sep 17 00:00:00 2001 From: Pascal Senn Date: Sun, 27 Aug 2023 23:45:19 +0200 Subject: [PATCH 1/2] Fixed an issue with conitnous task --- .../src/Subscriptions.Postgres/ContinuousTask.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/HotChocolate/Core/src/Subscriptions.Postgres/ContinuousTask.cs b/src/HotChocolate/Core/src/Subscriptions.Postgres/ContinuousTask.cs index b9cb2676357..1db8b793ac2 100644 --- a/src/HotChocolate/Core/src/Subscriptions.Postgres/ContinuousTask.cs +++ b/src/HotChocolate/Core/src/Subscriptions.Postgres/ContinuousTask.cs @@ -7,6 +7,7 @@ internal sealed class ContinuousTask : IAsyncDisposable private readonly CancellationTokenSource _completion = new(); private readonly Func _handler; private readonly Task _task; + private bool disposed; public ContinuousTask(Func handler) { @@ -46,13 +47,14 @@ private async Task RunContinuously() /// public async ValueTask DisposeAsync() { -#if NET8_0_OR_GREATER - await _completion.CancelAsync(); -#else - _completion.Cancel(); -#endif + if (disposed) + { + return; + } + + _completion.TryCancel(); _completion.Dispose(); - await _task; + disposed = true; } } From 80d0389437f8dcd9688d89b749a291ae80de16f8 Mon Sep 17 00:00:00 2001 From: Pascal Senn Date: Sun, 27 Aug 2023 23:52:57 +0200 Subject: [PATCH 2/2] Fixed an issue with conitnous task --- .../src/Subscriptions.Postgres/ContinuousTask.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/HotChocolate/Core/src/Subscriptions.Postgres/ContinuousTask.cs b/src/HotChocolate/Core/src/Subscriptions.Postgres/ContinuousTask.cs index 1db8b793ac2..443d5313b65 100644 --- a/src/HotChocolate/Core/src/Subscriptions.Postgres/ContinuousTask.cs +++ b/src/HotChocolate/Core/src/Subscriptions.Postgres/ContinuousTask.cs @@ -47,12 +47,20 @@ private async Task RunContinuously() /// public async ValueTask DisposeAsync() { - if (disposed) + if(disposed) { return; } - _completion.TryCancel(); + if(!_completion.IsCancellationRequested) + { +#if NET8_0_OR_GREATER + await _completion.CancelAsync(); +#else + _completion.Cancel(); +#endif + } + _completion.Dispose(); disposed = true;