From 1a5cf922a7c98030ddb48baacc5f7b85ac2d71ce Mon Sep 17 00:00:00 2001 From: PascalSenn Date: Thu, 31 Aug 2023 15:39:52 +0200 Subject: [PATCH] Fixed double dispose of continous task (#6484) --- .../src/Subscriptions.Postgres/ContinuousTask.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/HotChocolate/Core/src/Subscriptions.Postgres/ContinuousTask.cs b/src/HotChocolate/Core/src/Subscriptions.Postgres/ContinuousTask.cs index b9cb2676357..443d5313b65 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,22 @@ private async Task RunContinuously() /// public async ValueTask DisposeAsync() { + if(disposed) + { + return; + } + + if(!_completion.IsCancellationRequested) + { #if NET8_0_OR_GREATER - await _completion.CancelAsync(); + await _completion.CancelAsync(); #else - _completion.Cancel(); + _completion.Cancel(); #endif + } + _completion.Dispose(); - await _task; + disposed = true; } }