Skip to content

Commit a394090

Browse files
authored
Merge pull request #220 from OmniSharp/fix/cancellation
Added start of request call to request so that we don't leak cancella…
2 parents db18a94 + 3629cec commit a394090

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/JsonRpc/IRequestRouter.cs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public interface IRequestRouter
1010
Task RouteNotification(Notification notification, CancellationToken token);
1111
Task<ErrorResponse> RouteRequest(Request request, CancellationToken token);
1212
void CancelRequest(object id);
13+
void StartRequest(object id);
1314
}
1415

1516
public interface IRequestRouter<TDescriptor> : IRequestRouter

src/JsonRpc/InputHandler.cs

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ private void HandleRequest(string request)
179179
var descriptor = _requestRouter.GetDescriptor(item.Request);
180180
if (descriptor is null) continue;
181181
var type = _requestProcessIdentifier.Identify(descriptor);
182+
_requestRouter.StartRequest(item.Request.Id);
182183
_scheduler.Add(
183184
type,
184185
item.Request.Method,

src/JsonRpc/RequestRouterBase.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -185,20 +185,21 @@ public virtual async Task<ErrorResponse> RouteRequest(TDescriptor descriptor, Re
185185

186186
public void CancelRequest(object id)
187187
{
188-
var idValue = GetId(id);
189-
if (_requests.TryGetValue(idValue, out var cts))
188+
if (_requests.TryGetValue(GetId(id), out var cts))
190189
{
191190
cts.Cancel();
192191
}
193192
else
194193
{
195-
cts = new CancellationTokenSource();
196-
_requests.TryAdd(idValue, cts);
197-
cts.Cancel();
198194
_logger.LogDebug("Request {Id} was not found to cancel, stubbing it in.", id);
199195
}
200196
}
201197

198+
public void StartRequest(object id)
199+
{
200+
_requests.TryAdd(GetId(id), new CancellationTokenSource());
201+
}
202+
202203
private string GetId(object id)
203204
{
204205
if (id is string s)

0 commit comments

Comments
 (0)