Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly handle task cancelation in ResponseRouter #1190

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Client/LanguageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,20 @@ private void RegisterCapabilities(ClientCapabilities capabilities)
}

public async Task Shutdown()
{
await Shutdown(CancellationToken.None);
}

public async Task Shutdown(CancellationToken token)
{
if (_connection.IsOpen)
{
await this.RequestShutdown().ConfigureAwait(false);
try
{
await this.RequestShutdown(token).ConfigureAwait(false);
}
catch (TaskCanceledException) { }

this.SendExit();
}

Expand Down
11 changes: 9 additions & 2 deletions src/JsonRpc/ResponseRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ public async Task<TResponse> Returning<TResponse>(CancellationToken cancellation
var tcs = new TaskCompletionSource<JToken>();
_router.Requests.TryAdd(nextId, ( _method, tcs ));

cancellationToken.ThrowIfCancellationRequested();

try
{
cancellationToken.ThrowIfCancellationRequested();

_router.OutputHandler.Value.Send(
new OutgoingRequest
{
Expand All @@ -117,6 +117,13 @@ public async Task<TResponse> Returning<TResponse>(CancellationToken cancellation
() =>
{
if (tcs.Task.IsCompleted) return;

if (cancellationToken.IsCancellationRequested)
{
tcs.SetCanceled();
return;
}

_router.CancelRequest(new CancelParams { Id = nextId });
}
);
Expand Down
Loading