diff --git a/src/Features/LanguageServer/Protocol/Handler/RequestExecutionQueue.cs b/src/Features/LanguageServer/Protocol/Handler/RequestExecutionQueue.cs index 1ab2635171c11..d76f788679e3f 100644 --- a/src/Features/LanguageServer/Protocol/Handler/RequestExecutionQueue.cs +++ b/src/Features/LanguageServer/Protocol/Handler/RequestExecutionQueue.cs @@ -178,6 +178,11 @@ public void Shutdown() _requestTelemetryLogger, combinedCancellationToken); + // Run a continuation to ensure the cts is disposed of. + // We pass CancellationToken.None as we always want to dispose of the source + // even when the request is cancelled or the queue is shutting down. + _ = resultTask.ContinueWith(_ => combinedTokenSource.Dispose(), CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default); + var didEnqueue = _queue.TryEnqueue((item, combinedCancellationToken)); // If the queue has been shut down the enqueue will fail, so we just fault the task immediately.