Skip to content

Added start of request call to request so that we don't leak cancella… #220

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

Merged
merged 1 commit into from
Mar 17, 2020
Merged
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
1 change: 1 addition & 0 deletions src/JsonRpc/IRequestRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public interface IRequestRouter
Task RouteNotification(Notification notification, CancellationToken token);
Task<ErrorResponse> RouteRequest(Request request, CancellationToken token);
void CancelRequest(object id);
void StartRequest(object id);
}

public interface IRequestRouter<TDescriptor> : IRequestRouter
Expand Down
1 change: 1 addition & 0 deletions src/JsonRpc/InputHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ private void HandleRequest(string request)
var descriptor = _requestRouter.GetDescriptor(item.Request);
if (descriptor is null) continue;
var type = _requestProcessIdentifier.Identify(descriptor);
_requestRouter.StartRequest(item.Request.Id);
_scheduler.Add(
type,
item.Request.Method,
Expand Down
11 changes: 6 additions & 5 deletions src/JsonRpc/RequestRouterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,21 @@ public virtual async Task<ErrorResponse> RouteRequest(TDescriptor descriptor, Re

public void CancelRequest(object id)
{
var idValue = GetId(id);
if (_requests.TryGetValue(idValue, out var cts))
if (_requests.TryGetValue(GetId(id), out var cts))
{
cts.Cancel();
}
else
{
cts = new CancellationTokenSource();
_requests.TryAdd(idValue, cts);
cts.Cancel();
_logger.LogDebug("Request {Id} was not found to cancel, stubbing it in.", id);
}
}

public void StartRequest(object id)
{
_requests.TryAdd(GetId(id), new CancellationTokenSource());
}

private string GetId(object id)
{
if (id is string s)
Expand Down