Skip to content

Commit

Permalink
Fixed double dispose of continous task (#6484)
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalSenn authored Aug 31, 2023
1 parent 7818a9f commit 1a5cf92
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/HotChocolate/Core/src/Subscriptions.Postgres/ContinuousTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ internal sealed class ContinuousTask : IAsyncDisposable
private readonly CancellationTokenSource _completion = new();
private readonly Func<CancellationToken, Task> _handler;
private readonly Task _task;
private bool disposed;

public ContinuousTask(Func<CancellationToken, Task> handler)
{
Expand Down Expand Up @@ -46,13 +47,22 @@ private async Task RunContinuously()
/// <inheritdoc />
public async ValueTask DisposeAsync()

Check warning on line 48 in src/HotChocolate/Core/src/Subscriptions.Postgres/ContinuousTask.cs

View workflow job for this annotation

GitHub Actions / Merge and Upload Coverage

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
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;
}
}

0 comments on commit 1a5cf92

Please sign in to comment.