Remove request from requests dict after it was handled. This was a memory leak!
This commit is contained in:
parent
bc19a315da
commit
036897ecab
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hibas123/jrpcgen",
|
"name": "@hibas123/jrpcgen",
|
||||||
"version": "1.2.19",
|
"version": "1.2.20",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"packageManager": "yarn@3.1.1",
|
"packageManager": "yarn@3.1.1",
|
||||||
|
@ -89,27 +89,41 @@ public class JRpcClient
|
|||||||
|
|
||||||
var task = new TaskCompletionSource<JsonNode?>();
|
var task = new TaskCompletionSource<JsonNode?>();
|
||||||
this.Requests.Add(id, task);
|
this.Requests.Add(id, task);
|
||||||
_ = Task.Run(async () =>
|
|
||||||
{
|
|
||||||
await this.Transport.Write(request.ToJsonString());
|
|
||||||
});
|
|
||||||
|
|
||||||
if (this.Timeout.HasValue)
|
try
|
||||||
{
|
{
|
||||||
if (await Task.WhenAny(task.Task, Task.Delay(this.Timeout.Value)) == task.Task)
|
_ = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
return await task.Task;
|
try
|
||||||
|
{
|
||||||
|
await this.Transport.Write(request.ToJsonString());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
task.SetException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (this.Timeout.HasValue)
|
||||||
|
{
|
||||||
|
if (await Task.WhenAny(task.Task, Task.Delay(this.Timeout.Value)) == task.Task)
|
||||||
|
{
|
||||||
|
return await task.Task;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new JRpcTimeoutException();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.Requests.Remove(id);
|
return await task.Task;
|
||||||
throw new JRpcTimeoutException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
finally
|
||||||
{
|
{
|
||||||
return await task.Task;
|
this.Requests.Remove(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user